FVector2 / FVector3 / FVector4

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

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

Example FVector tipe adalah single-precision (float32) kelas vektor yang digunakan secara internal oleh array data elemen vertex. Mereka menukar efisiensi memori single precision dengan double precision dari Vector2, Vector3, Vector4 kelas yang digunakan untuk posisi scene graph. Pada praktiknya Anda akan paling sering membuat nilai-nilai ini saat mengisi VertexElementFVector.set_data().

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

FVector2

Vektor float single-precision dua komponen dengan x dan y komponen.

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

Example

ExampleExampleExampleExample
xfloatbaca/tulisKomponen pertama.
yfloatbaca/tulisKomponen kedua.

Example

ExampleExampleExample
length()floatPanjang Euclidean vektor: sqrt(x² + y²).
normalize()FVector2Kembalikan salinan dengan panjang satu unit. Mengembalikan FVector2(0, 0) untuk vektor nol.
dot(other)floatProduk titik dengan other.
FVector2.parse(s)FVector2Mengurai string yang dipisahkan spasi "x y" menjadi sebuah FVector2.

Example +, -, * (scalar), / (scalar), dan == operator.

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 float presisi tunggal 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 sebuah Vector3, Vector4, atau FVector4 sebagai argumen pertama untuk mengonversi dari tipe-tipe tersebut.

Example

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

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

Metode pabrik statis

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)

Metode instance

ExampleExampleExample
normalize()FVector3Kembalikan salinan dengan panjang satu. Mengembalikan vektor nol untuk masukan dengan panjang nol.

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 float presisi tunggal empat komponen dengan x, y, z, dan w komponen. Ini adalah tipe penyimpanan 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 sebuah FVector3, Vector3, atau Vector4 sebagai argumen pertamanya.

Example

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

Mendukung akses indeks: v[0] melalui 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

Hubungan dengan vektor presisi ganda

Presisi tunggalPresisi gandaPenggunaan umum
FVector2Vector2Koordinat UV disimpan dalam elemen vertex
FVector3Vector3Normal, tangent disimpan dalam elemen vertex
FVector4Vector4Example VertexElementFVector.data entri; juga konversi titik kontrol

Saat mengatur data elemen vertex, Anda dapat memberikan salah satu kelas presisi. set_data() mengonversi Vector2/Vector3 nilai menjadi FVector4 secara otomatis.


Lihat Juga

 Bahasa Indonesia