FVector2, FVector3, FVector4 — Aspose.3D Python API Reference
Pakotne: aspose.threed.utilities (aspose-3d-foss 26.1.0)
Example FVector tipi ir vienkāršas precizitātes (float32) vektoru klases, kas tiek izmantotas iekšēji virsotnes elementu datu masīvos. Tās apmaina vienkāršas precizitātes atmiņas efektivitāti pret dubultās precizitātes Vector2, Vector3, Vector4 klases, kas tiek izmantotas ainas grafika pozīcijām. Praktiski jūs visbiežāk izveidosiet šīs vērtības, kad aizpildīsiet VertexElementFVector.set_data().
from aspose.threed.utilities import FVector2, FVector3, FVector4FVector2
Divkomponentu vienkāršprecizitātes peldošā komata vektors ar x un y komponentes.
class FVector2:
def __init__(self, x: float = 0.0, y: float = 0.0): ...Example
| Example | Example | Example | Example |
|---|---|---|---|
x | float | lasīt/rakstīt | Pirmā komponente. |
y | float | lasīt/rakstīt | Otrā komponente. |
Example
| Example | Example | Example |
|---|---|---|
length() | float | Vektora Eiklīda garums: sqrt(x² + y²). |
normalize() | FVector2 | Atgriež vienības garuma kopiju. Atgriež FVector2(0, 0) nullvektora gadījumā. |
dot(other) | float | Skalarprodukts ar other. |
FVector2.parse(s) | FVector2 | Parsēt atstarpes atdalītu virkni "x y" par FVector2. |
Example +, -, * (skalārs), / (skalārs), un == operatori.
Example
from aspose.threed.utilities import FVector2
uv = FVector2(0.5, 0.25)
print(uv.x, uv.y) # 0.5 0.25
print(uv.length()) # ~0.559
unit = uv.normalize()
print(round(unit.length(), 6)) # 1.0
a = FVector2(1.0, 0.0)
b = FVector2(0.0, 1.0)
print(a.dot(b)) # 0.0FVector3
Trīs komponentu vienkāršas precizitātes peldošā komata vektors ar x, y, un z komponentes.
class FVector3:
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0): ...FVector3 arī pieņem Vector3, Vector4, vai FVector4 kā tā pirmo argumentu, lai konvertētu no šiem tipiem.
Example
| Example | Example | Example | Example |
|---|---|---|---|
x | float | lasīt/rakstīt | Pirmais komponents. |
y | float | lasīt/rakstīt | Otra sastāvdaļa. |
z | float | lasīt/rakstīt | Trešā sastāvdaļa. |
Atbalsta piekļuvi pēc indeksa: v[0], v[1], v[2].
Statiskās ražotāja metodes
| Example | Example | Example |
|---|---|---|
FVector3.zero() | FVector3 | (0, 0, 0) |
FVector3.one() | FVector3 | (1, 1, 1) |
FVector3.unit_x() | FVector3 | (1, 0, 0) |
FVector3.unit_y() | FVector3 | (0, 1, 0) |
FVector3.unit_z() | FVector3 | (0, 0, 1) |
Instanču metodes
| Example | Example | Example |
|---|---|---|
normalize() | FVector3 | Atgriež vienības garuma kopiju. Atgriež nullvektoru, ja ievade ir nulles garuma. |
Example
from aspose.threed.utilities import FVector3
n = FVector3(0.0, 1.0, 0.0)
print(n.normalize()) # FVector3(0.0, 1.0, 0.0)
up = FVector3.unit_y()
print(up.x, up.y, up.z) # 0.0 1.0 0.0
# Convert from Vector3
from aspose.threed.utilities import Vector3
v = Vector3(1.0, 2.0, 3.0)
fv = FVector3(v)
print(fv) # FVector3(1.0, 2.0, 3.0)FVector4
Četru komponentu vienkāršas precizācijas peldošā komata vektors ar x, y, z, un w komponentēm. Šis ir glabāšanas tips, ko izmanto VertexElementFVector.data.
class FVector4:
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0, w: float = 0.0): ...FVector4 arī pieņem FVector3, Vector3, vai Vector4 kā tā pirmais arguments.
Example
| Example | Example | Example | Example |
|---|---|---|---|
x | float | lasīt/rakstīt | Pirmais komponents. |
y | float | lasīt/rakstīt | Otrais komponents. |
z | float | lasīt/rakstīt | Trešais komponents. |
w | float | lasīt/rakstīt | Ceturtais komponents. |
Atbalsta indeksa piekļuvi: v[0] caur v[3].
Example
from aspose.threed.utilities import FVector4, FVector3
# Direct construction
normal = FVector4(0.0, 0.0, 1.0, 0.0)
print(normal.z) # 1.0
# From FVector3
fv3 = FVector3(0.0, 1.0, 0.0)
fv4 = FVector4(fv3, 0.0)
print(fv4) # FVector4(0.0, 1.0, 0.0, 0.0)
# Index access
print(fv4[1]) # 1.0
fv4[3] = 1.0
print(fv4.w) # 1.0Attiecības ar dubultas precizitātes vektoriem
| Vienkāršā precizitāte | Dubultā precizitāte | Tipiska lietošana |
|---|---|---|
FVector2 | Vector2 | UV koordinātas, kas saglabātas virsotnes elementos |
FVector3 | Vector3 | Normāles, tangenti, kas saglabāti virsotnes elementos |
FVector4 | Vector4 | Example VertexElementFVector.data ieraksti; arī kontroles punkta pārveidošana |
Iestatot virsotnes elementa datus, varat nodot kādu no precizitātes klasēm. set_data() pārvērš Vector2/Vector3 vērtības uz FVector4 automātiski.