FVector2 / FVector3 / FVector4

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, FVector4

FVector2

Dvojkomponentový jednopresnostný float vektor s x a y komponentami.

class FVector2:
    def __init__(self, x: float = 0.0, y: float = 0.0): ...

Example

ExampleExampleExampleExample
xfloatčítanie/zápisPrvá komponenta.
yfloatčítanie/zápisDruhá komponenta.

Example

ExampleExampleExample
length()floatEuklidovská dĺžka vektora: sqrt(x² + y²).
normalize()FVector2Vráti kópiu s jednotkovou dĺžkou. Vráti FVector2(0, 0) pre nulový vektor.
dot(other)floatSkalárny súčin s other.
FVector2.parse(s)FVector2Rozparsovať 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.0

FVector3

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

ExampleExampleExampleExample
xfloatčítanie/zápisPrvá komponenta.
yfloatčítanie/zápisDruhá komponenta.
zfloatčítanie/zápisTretia komponenta.

Podporuje indexový prístup: v[0], v[1], v[2].

Statické továrenské metódy

ExampleExampleExample
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

ExampleExampleExample
normalize()FVector3Vrá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

ExampleExampleExampleExample
xfloatčítanie/zápisPrvá zložka.
yfloatčítanie/zápisDruhá zložka.
zfloatčítanie/zápisTretia zložka.
wfloatčí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.0

Vzťah k dvojitéj presnosti vektorov

JednoprecíznyDvojitá presnosťTypické použitie
FVector2Vector2UV súradnice uložené v prvkoch vrcholov
FVector3Vector3Normály, tangenty uložené v prvkoch vrcholov
FVector4Vector4Example 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.


Pozri tiež

 Slovenčina