FVector2 / FVector3 / FVector4

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

بسته: aspose.threed.utilities (aspose-3d-foss 26.1.0)

Example FVector نوع‌ها تک‌دقت هستند (float32) کلاس‌های برداری که به‌صورت داخلی توسط آرایه‌های داده عنصر راس استفاده می‌شوند. آن‌ها کارایی حافظه تک‌دقت را در مقابل double precision کلاس‌های Vector2, Vector3, Vector4 کلاس‌های مورد استفاده برای موقعیت‌های scene graph. در عمل، شما بیشتر اوقات این مقادیر را هنگام پر کردن VertexElementFVector.set_data().

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

FVector3

یک بردار float تک‌دقت دو مؤلفه‌ای با 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 +, -, * (اسکلار)،, / (اسکلار)، و == عملگرها.

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

یک بردار شناور تک‌دقت سه‌جزئی با 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

یک بردار شناور تک‌دقت چهار مؤلفه‌ای با 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 ورودی‌ها؛ همچنین تبدیل control point

هنگام تنظیم داده‌های vertex element، می‌توانید یکی از کلاس‌های precision را پاس کنید. set_data() تبدیل می‌کند Vector2/Vector3 مقدارها به FVector4 به‌صورت خودکار.


موارد مرتبط

 فارسی