FVector2 / FVector3 / FVector4

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

แพคเกจ: aspose.threed.utilities (aspose-3d-foss 26.1.0)

Example FVector ประเภทเป็น single-precision (float32) คลาสเวกเตอร์ที่ใช้ภายในโดยอาร์เรย์ข้อมูลองค์ประกอบเวอร์เท็กซ์ พวกมันแลกเปลี่ยนประสิทธิภาพการใช้หน่วยความจำของ single precision กับ double precision ของ Vector2, Vector3, Vector4 คลาสที่ใช้สำหรับตำแหน่งในกราฟฉาก ในการปฏิบัติจริงคุณมักจะสร้างค่าเหล่านี้บ่อยที่สุดเมื่อทำการเติมข้อมูล VertexElementFVector.set_data().

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

FVector2

เวกเตอร์ float single-precision สองส่วนประกอบที่มี x และ y ส่วนประกอบ.

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

Example

ExampleExampleExampleExample
xfloatอ่าน/เขียนส่วนประกอบแรก.
yfloatอ่าน/เขียนส่วนประกอบที่สอง.

Example

ExampleExampleExample
length()floatความยาวยูคลิดของเวกเตอร์: sqrt(x² + y²).
normalize()FVector2คืนสำเนาความยาวหน่วย คืนค่า FVector2(0, 0) สำหรับเวกเตอร์ศูนย์.
dot(other)floatผลคูณจุดกับ other.
FVector2.parse(s)FVector2แยกสตริงที่คั่นด้วยช่องว่าง "x y" เป็น FVector2.

Example +, -, * (scalar), / (scalar), และ == ตัวดำเนินการ.

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

เวกเตอร์ single-precision float ที่มีสามส่วนประกอบ x, y, และ z ส่วนประกอบ.

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

FVector3 ยังรับ Vector3, Vector4, หรือ FVector4 เป็นอาร์กิวเมนต์แรกเพื่อแปลงจากประเภทเหล่านั้น.

Example

ExampleExampleExampleExample
xfloatอ่าน/เขียนส่วนประกอบแรก.
yfloatอ่าน/เขียนส่วนที่สอง.
zfloatอ่าน/เขียนส่วนที่สาม.

รองรับการเข้าถึงโดยใช้ดัชนี: v[0], v[1], v[2].

เมธอดแฟกทอรีแบบสถิตย์

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)

เมธอดของอินสแตนซ์

ExampleExampleExample
normalize()FVector3คืนสำเนาที่มีความยาวหน่วยหนึ่ง คืนเวกเตอร์ศูนย์สำหรับอินพุตที่มีความยาวศูนย์.

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

เวกเตอร์ float ความแม่นยำเดี่ยวสี่ส่วนประกอบที่มี x, y, z, และ w ส่วนประกอบ. นี่คือประเภทการจัดเก็บที่ใช้โดย VertexElementFVector.data.

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

FVector4 ยังรับ FVector3, Vector3, หรือ Vector4 เป็นอาร์กิวเมนต์แรกของมัน.

Example

ExampleExampleExampleExample
xfloatอ่าน/เขียนส่วนประกอบแรก.
yfloatอ่าน/เขียนส่วนประกอบที่สอง.
zfloatอ่าน/เขียนส่วนประกอบที่สาม.
wfloatอ่าน/เขียนส่วนประกอบที่สี่.

รองรับการเข้าถึงโดยดัชนี: v[0] ผ่าน 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

ความสัมพันธ์กับเวกเตอร์ความแม่นยำคู่

ความแม่นยำแบบเดี่ยวความแม่นยำแบบคู่การใช้งานทั่วไป
FVector2Vector2พิกัด UV ที่เก็บในองค์ประกอบเวอร์เท็กซ์
FVector3Vector3เวกเตอร์ปกติและแทนเจนท์ที่เก็บในองค์ประกอบเวอร์เท็กซ์
FVector4Vector4Example VertexElementFVector.data รายการ; รวมถึงการแปลงจุดควบคุม

เมื่อกำหนดข้อมูลองค์ประกอบเวอร์เท็กซ์ คุณสามารถส่งคลาสความแม่นยำได้หนึ่งในสองแบบ. set_data() แปลง Vector2/Vector3 ค่าเป็น FVector4 โดยอัตโนมัติ.


ดูเพิ่มเติม

 ภาษาไทย