FVector2 / FVector3 / FVector4

FVector2, FVector3, FVector4 — Aspose.3D Python API Reference

Pakej: aspose.threed.utilities (aspose-3d-foss 26.1.0)

Enumerations FVector jenis adalah single-precision (float32) kelas vektor yang digunakan secara dalaman oleh tatasusunan data elemen vertex. Mereka menukar kecekapan memori single precision berbanding double precision bagi Vector2, Vector3, Vector4 kelas yang digunakan untuk kedudukan graf adegan. Dalam amalan, anda biasanya akan mencipta nilai-nilai ini semasa mengisi VertexElementFVector.set_data().

from aspose.threed.utilities import FVector2, FVector3, FVector4

FVector2

Vektor titik apung single-precision dua-komponen dengan x dan y komponen.

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

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
xfloatbaca/tulisKomponen pertama.
yfloatbaca/tulisKomponen kedua.

Enumerations

EnumerationsEnumerationsEnumerations
length()floatPanjang Euclidean vektor: sqrt(x² + y²).
normalize()FVector2Kembalikan salinan panjang unit. Mengembalikan FVector2(0, 0) bagi vektor sifar.
dot(other)floatHasil darab titik dengan other.
FVector2.parse(s)FVector2Huraikan rentetan yang dipisahkan dengan ruang "x y" menjadi satu FVector2.

Enumerations +, -, * (skalar), / (skalar), dan == operator.

Enumerations

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 titik terapung single-precision tiga komponen dengan x, y, dan z komponen.

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

FVector3 juga menerima satu Vector3, Vector4, atau FVector4 sebagai argumen pertamanya untuk menukar dari jenis-jenis tersebut.

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
xfloatbaca/tulisKomponen pertama.
yfloatbaca/tulisKomponen kedua.
zfloatbaca/tulisKomponen ketiga.

Menyokong akses indeks: v[0], v[1], v[2].

Kaedah kilang statik

EnumerationsEnumerationsEnumerations
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)

Kaedah contoh

EnumerationsEnumerationsEnumerations
normalize()FVector3Kembalikan salinan panjang unit. Mengembalikan vektor sifar untuk input panjang sifar.

Enumerations

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 titik terapung tepat tunggal empat komponen dengan x, y, z, dan w komponen. Ini adalah jenis storan yang digunakan oleh VertexElementFVector.data.

class FVector4:
    def __init__(self, x: float = 0.0, y: float = 0.0, z: float = 0.0, w: float = 0.0): ...

FVector4 juga menerima satu FVector3, Vector3, atau Vector4 sebagai argumen pertamanya.

Enumerations

EnumerationsEnumerationsEnumerationsEnumerations
xfloatbaca/tulisKomponen pertama.
yfloatbaca/tulisKomponen kedua.
zfloatbaca/tulisKomponen ketiga.
wfloatbaca/tulisKomponen keempat.

Menyokong akses indeks: v[0] melalui v[3].

Enumerations

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

Hubungan dengan double-precision vectors

Presisi tunggalPresisi bergandaPenggunaan biasa
FVector2Vector2Koordinat UV disimpan dalam elemen verteks
FVector3Vector3Normal, tangen disimpan dalam elemen verteks
FVector4Vector4Enumerations VertexElementFVector.data entri; juga penukaran titik kawalan

Apabila menetapkan data elemen verteks, anda boleh menghantar mana-mana kelas presisi. set_data() menukar Vector2/Vector3 nilai kepada FVector4 secara automatik.


Lihat Juga

 Bahasa Melayu