Matrix4

Methods

Matrix4 là một ma trận 4×4 độ chính xác kép được lưu trữ theo thứ tự hàng với 16 phần tử (m00m33).

Methods: aspose.threed.utilities

from aspose.threed.utilities import Matrix4

Methods

MethodsMethods
Matrix4()Ma trận đơn vị
Matrix4(m00, m01, ..., m33)Bộ khởi tạo 16 phần tử rõ ràng (theo thứ tự hàng)
Matrix4(values)Khởi tạo từ một danh sách gồm 16 float giá trị

Thuộc tính phần tử

Các phần tử được đặt tên mRC trong đó R là hàng (0–3) và C là cột (0–3). Ví dụ, m03 là hàng 0, cột 3 (dịch chuyển X khi ma trận mã hoá một phép biến đổi). Tất cả 16 thuộc tính (m00 đến m33) có thể đọc và ghi.

Ma trận cũng có thể được truy cập bằng chỉ mục phẳng: mat[0]mat[15].

Thuộc tính tính toán

MethodsMethodsMethods
determinantfloatĐịnh thức vô hướng của ma trận

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

MethodsKiểu trả vềMethods
Matrix4.get_identity()Matrix4Trả về một ma trận đơn vị
Matrix4.translate(tx, ty, tz)Matrix4Ma trận dịch chuyển; cũng chấp nhận một Vector3 hoặc một số vô hướng duy nhất cho dịch chuyển đồng nhất
Matrix4.scale(sx, sy, sz)Matrix4Ma trận tỉ lệ; cũng chấp nhận một Vector3 hoặc một số vô hướng duy nhất cho tỷ lệ đồng nhất
Matrix4.rotate(angle, axis)Matrix4Ma trận quay từ góc (radian) và Vector3 trục; cũng chấp nhận một Quaternion là đối số duy nhất
Matrix4.rotate_from_euler(rx, ry, rz)Matrix4Ma trận quay từ các góc Euler (radian); cũng chấp nhận một Vector3

Các phương thức Instance

MethodsKiểu trả vềMethods
concatenate(m2)Matrix4Trả về tích ma trận self × m2
normalize()Matrix4Trả về một bản sao với các trục quay được chuẩn hoá lại (loại bỏ tỷ lệ khỏi các cột quay)
transpose()Matrix4Trả về ma trận chuyển vị
inverse()Matrix4Trả về ma trận nghịch đảo; ném ra ValueError nếu ma trận là đơn trị
decompose(translation, scaling, rotation)NonePhân tách thành các thành phần TRS. Kết quả được ghi vào các danh sách một phần tử: translation[0]Vector3, scaling[0]Vector3, rotation[0]Quaternion
set_trs(translation, rotation, scale)NoneĐặt ma trận tại chỗ từ phép dịch Vector3, quay Quaternion hoặc Vector3 (Euler), và tỷ lệ Vector3
to_array()list[float]Trả về 16 phần tử dưới dạng danh sách phẳng

Methods

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

# Build a transform: translate (5, 0, 0), rotate 90 deg around Y, scale 2x
t = Matrix4.translate(5.0, 0.0, 0.0)
r = Matrix4.rotate(math.radians(90), Vector3(0, 1, 0))
s = Matrix4.scale(2.0, 2.0, 2.0)

# Combine: scale first, then rotate, then translate
combined = t.concatenate(r.concatenate(s))

# Decompose the result back into TRS
translation = [None]
scaling     = [None]
rotation    = [None]
combined.decompose(translation, scaling, rotation)

print(translation[0])   # Vector3(5.0, 0.0, 0.0)
print(scaling[0])       # Vector3(2.0, 2.0, 2.0)

# Retrieve from a node's global transform
from aspose.threed import Scene
scene = Scene()
node = scene.root_node.create_child_node("box")
node.transform.translation = Vector3(10.0, 0.0, 0.0)
world_mat = node.global_transform.transform_matrix
print(world_mat.m03)   # 10.0 — translation X

Xem thêm

 Tiếng Việt