Quaternion

Methods

Quaternion đại diện cho một quaternion đơn vị được sử dụng để mã hoá các phép quay 3D. Khác với góc Euler, quaternion tránh hiện tượng gimbal lock và nội suy một cách mượt mà. The Transform.rotation thuộc tính trên một nút cảnh lưu trữ một Quaternion.

Các thành phần được lưu trữ dưới dạng (w, x, y, z) trong đó w là phần vô hướng và (x, y, z) tạo thành phần vectơ.

from aspose.threed.utilities import Quaternion
import math

# Identity quaternion (no rotation)
q = Quaternion()   # w=1, x=0, y=0, z=0

# Rotation of 90 degrees around the Y axis
q = Quaternion.from_euler_angle(0.0, math.radians(90), 0.0)

Methods: aspose.threed.utilities

from aspose.threed.utilities import Quaternion

Methods

MethodsMethods
Quaternion()Quaternion đồng nhất (w=1, x=0, y=0, z=0)
Quaternion(w, x, y, z)Bộ khởi tạo thành phần rõ ràng

Methods

MethodsMethodsMethods
wfloatPhần vô hướng (thực)
xfloatThành phần x của vectơ
yfloatThành phần y của vector
zfloatThành phần z của vector
lengthfloatĐộ lớn của quaternion

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

MethodsKiểu trả vềMethods
Quaternion.from_euler_angle(pitch, yaw, roll)QuaternionXây dựng từ các góc Euler tính bằng radian (pitch=X, yaw=Y, roll=Z). Cũng chấp nhận một Vector3 là đối số đầu tiên
Quaternion.from_angle_axis(angle, axis)QuaternionXây dựng từ một góc (radian) và một Vector3 trục
Quaternion.from_rotation(orig, dest)QuaternionXoay cung tròn ngắn nhất từ hướng orig đến hướng dest
Quaternion.interpolate(t, from_q, to_q)QuaternionNội suy SLERP; t trong [0, 1]
Quaternion.slerp(t, v1, v2)QuaternionTên thay thế cho interpolate

Các phương thức Instance

MethodsKiểu trả vềMethods
normalize()QuaternionTrả về một bản sao có độ dài đơn vị
conjugate()QuaternionTrả về phần liên hợp (w, -x, -y, -z)
inverse()QuaternionTrả về nghịch đảo nhân; phát sinh ValueError nếu độ dài bằng không
dot(q)floatTích vô hướng với một quaternion khác
concat(rhs)QuaternionTích Hamilton (kết hợp của hai phép quay)
euler_angles()Vector3Trích xuất các góc Euler (radians) dưới dạng Vector3(roll, pitch, yaw)
to_matrix(translation=None)Matrix4Chuyển đổi thành ma trận quay 4×4; tùy chọn nhúng một phép dịch Vector3
to_angle_axis(angle, axis)NonePhân tách thành góc (radians) và trục; kết quả được ghi vào các danh sách một phần tử angle[0]axis[0]

Methods

from aspose.threed import Scene
from aspose.threed.utilities import Quaternion, Vector3
import math

scene = Scene()
node = scene.root_node.create_child_node("rotated_box")

# Rotate 45 degrees around the Y axis
angle = math.radians(45)
q = Quaternion.from_euler_angle(0.0, angle, 0.0)
node.transform.rotation = q

# SLERP between two rotations
q_start = Quaternion.from_euler_angle(0, 0, 0)
q_end   = Quaternion.from_euler_angle(0, math.pi, 0)
q_mid   = Quaternion.slerp(0.5, q_start, q_end)

# Convert to matrix (useful for manual transforms)
mat = q.to_matrix()

# Extract Euler angles back
angles = q.euler_angles()   # Vector3(roll, pitch, yaw)
print(math.degrees(angles.y))   # ~45.0

Xem thêm

 Tiếng Việt