FVector2 / FVector3 / FVector4

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

Gói: aspose.threed.utilities (aspose-3d-foss 26.1.0)

Example FVector các kiểu là độ chính xác đơn (float32) các lớp vector được sử dụng nội bộ bởi các mảng dữ liệu phần tử đỉnh. Chúng đánh đổi hiệu quả bộ nhớ của độ chính xác đơn so với độ chính xác đôi của Vector2, Vector3, Vector4 các lớp được dùng cho vị trí trong đồ thị cảnh. Trong thực tế, bạn sẽ thường tạo các giá trị này khi điền VertexElementFVector.set_data().

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

FVector2

Một vector float độ chính xác đơn hai thành phần với xy các thành phần.

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

Example

ExampleExampleExampleExample
xfloatđọc/ghiThành phần đầu tiên.
yfloatđọc/ghiThành phần thứ hai.

Example

ExampleExampleExample
length()floatĐộ dài Euclid của vector: sqrt(x² + y²).
normalize()FVector2Trả về một bản sao có độ dài đơn vị. Trả về FVector2(0, 0) cho vector zero.
dot(other)floatTích vô hướng với other.
FVector2.parse(s)FVector2Phân tích một chuỗi phân tách bằng dấu cách "x y" thành một FVector2.

Example +, -, * (scalar), / (scalar), và == toán tử.

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

Một vector số thực đơn độ chính xác đơn có ba thành phần với x, y, và z các thành phần.

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

FVector3 cũng chấp nhận một Vector3, Vector4, hoặc FVector4 làm đối số đầu tiên để chuyển đổi từ các kiểu đó.

Example

ExampleExampleExampleExample
xfloatđọc/ghiThành phần đầu tiên.
yfloatđọc/ghiThành phần thứ hai.
zfloatđọc/ghiThành phần thứ ba.

Hỗ trợ truy cập theo chỉ mục: v[0], v[1], v[2].

Các phương thức tạo tĩnh

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)

Phương thức thể hiện

ExampleExampleExample
normalize()FVector3Trả về một bản sao có độ dài đơn vị. Trả về vector không cho đầu vào có độ dài bằng không.

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

Một vector số thực đơn chính xác một chiều có bốn thành phần với x, y, z, và w các thành phần. Đây là kiểu lưu trữ được sử dụng bởi VertexElementFVector.data.

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

FVector4 cũng chấp nhận một FVector3, Vector3, hoặc Vector4 là đối số đầu tiên của nó.

Example

ExampleExampleExampleExample
xfloatđọc/ghiThành phần đầu tiên.
yfloatđọc/ghiThành phần thứ hai.
zfloatđọc/ghiThành phần thứ ba.
wfloatđọc/ghiThành phần thứ tư.

Hỗ trợ truy cập theo chỉ mục: v[0] qua 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

Mối quan hệ với các vector độ chính xác đôi

Độ chính xác đơnĐộ chính xác đôiSử dụng điển hình
FVector2Vector2Tọa độ UV được lưu trong các phần tử đỉnh
FVector3Vector3Pháp tuyến, tiếp tuyến được lưu trong các phần tử đỉnh
FVector4Vector4Example VertexElementFVector.data các mục nhập; cũng chuyển đổi điểm điều khiển

Khi thiết lập dữ liệu phần tử đỉnh, bạn có thể truyền một trong các precision class. set_data() chuyển đổi Vector2/Vector3 các giá trị sang FVector4 tự động.


Xem thêm

 Tiếng Việt