FVector2, FVector3, FVector4 — Aspose.3D Python API Reference
Balík: aspose.threed.utilities (aspose-3d-foss 26.1.0)
Example FVector typy sú jednopresnostné (float32) triedy vektorov používané interne v poliach dát vrcholových elementov. Vymieňajú pamäťovú efektívnosť jednopresnosti za dvojitú presnosť Vector2, Vector3, Vector4 tried používaných pre pozície grafu scény. V praxi ich najčastejšie vytvoríte pri naplňovaní VertexElementFVector.set_data().
from aspose.threed.utilities import FVector2, FVector3, FVector4FVector2
Dvojkomponentový jednopresnostný float vektor s x a y komponentami.
class FVector2:
def __init__(self, x: float = 0.0, y: float = 0.0): ...Example
| Example | Example | Example | Example |
|---|---|---|---|
x | float | čítanie/zápis | Prvá komponenta. |
y | float | čítanie/zápis | Druhá komponenta. |
Example
| Example | Example | Example |
|---|---|---|
length() | float | Euklidovská dĺžka vektora: sqrt(x² + y²). |
normalize() | FVector2 | Vráti kópiu s jednotkovou dĺžkou. Vráti FVector2(0, 0) pre nulový vektor. |
dot(other) | float | Skalárny súčin s other. |
FVector2.parse(s) | FVector2 | Rozparsovať medzerou oddelený reťazec "x y" do FVector2. |
Example +, -, * (scalar), / (scalar), a == operátory.
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
Vektor s jednoprecíznym floatom a tromi komponentmi x, y, a z komponenty.
class FVector3:
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0): ...FVector3 takisto akceptuje Vector3, Vector4, alebo FVector4 ako svoj prvý argument na konverziu z týchto typov.
Example
| Example | Example | Example | Example |
|---|---|---|---|
x | float | čítanie/zápis | Prvá komponenta. |
y | float | čítanie/zápis | Druhá komponenta. |
z | float | čítanie/zápis | Tretia komponenta. |
Podporuje indexový prístup: v[0], v[1], v[2].
Statické továrenské metódy
| 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) |
Inštančné metódy
| Example | Example | Example |
|---|---|---|
normalize() | FVector3 | Vráti kópiu jednotkovej dĺžky. Pre vstup nulovej dĺžky vráti nulový vektor. |
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
Vektor s jednoprecíznym floatom a štyrmi komponentmi x, y, z, a w komponenty. Toto je typ úložiska používaný VertexElementFVector.data.
class FVector4:
def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0, w: float = 0.0): ...FVector4 aj akceptuje FVector3, Vector3, alebo Vector4 ako svoj prvý argument.
Example
| Example | Example | Example | Example |
|---|---|---|---|
x | float | čítanie/zápis | Prvá zložka. |
y | float | čítanie/zápis | Druhá zložka. |
z | float | čítanie/zápis | Tretia zložka. |
w | float | čítanie/zápis | Štvrtá zložka. |
Podporuje indexový prístup: v[0] cez 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.0Vzťah k dvojitéj presnosti vektorov
| Jednoprecízny | Dvojitá presnosť | Typické použitie |
|---|---|---|
FVector2 | Vector2 | UV súradnice uložené v prvkoch vrcholov |
FVector3 | Vector3 | Normály, tangenty uložené v prvkoch vrcholov |
FVector4 | Vector4 | Example VertexElementFVector.data záznamy; tiež konverzia kontrolných bodov |
Pri nastavovaní dát prvku vrcholu môžete odovzdať buď triedu precision class. set_data() konvertuje Vector2/Vector3 hodnoty na FVector4 automaticky.