Matrix4 — Aspose.3D FOSS for Java

Properties

Matrix4 là một ma trận 4x4 độ chính xác kép được sử dụng cho các phép biến đổi affine trong không gian 3D. Nó được trả về bởi Transform.getTransformMatrix()GlobalTransform.getTransformMatrix(), và có thể được xây dựng từ các phép phân tách dịch chuyển, quay và tỷ lệ (TRS).

Properties: com.aspose.threed

import com.aspose.threed.*;

Properties

PropertiesProperties
Matrix4()Tạo ma trận đơn vị
Matrix4(double m00, double m01, ... double m33)Tạo thành từ 16 phần tử riêng lẻ (theo thứ tự hàng)

Trường tĩnh

PropertiesPropertiesProperties
IDENTITYMatrix4Ma trận đơn vị 4x4

Trường công khai (Truy cập phần tử)

Matrix4 sử dụng các trường public để truy cập phần tử: m00, m01, … m33 (tổng cộng 16 trường, bố trí theo hàng).

Mẫu trườngPropertiesProperties
m00m33doubleCác phần tử ma trận riêng lẻ dưới dạng các trường công khai. Truy cập như mat.m00, mat.m01, v.v.

Các thành phần dịch nằm ở cột cuối cùng: m03 (X), m13 (Y), m23 (Z).

Properties

PropertiesKiểu trả vềProperties
multiply(Matrix4 other)Matrix4Phép nhân ma trận; trả về một ma trận mới
inverse()Matrix4Trả về ma trận nghịch đảo
transpose()Matrix4Trả về ma trận chuyển vị
decompose(Vector3 translation, Vector3 scaling, Quaternion rotation)booleanStub: luôn trả về false. Dự định phân tách ma trận thành các thành phần TRS, nhưng chưa được triển khai.
determinant()doubleTrả về định thức của ma trận
transformPoint(Vector3 point)Vector3Biến đổi một điểm (áp dụng đầy đủ phép dịch + quay + tỉ lệ)
transformDirection(Vector3 direction)Vector3Biến đổi một vector hướng (áp dụng quay + tỉ lệ, bỏ qua phép dịch)

Phương thức tĩnh

PropertiesKiểu trả vềProperties
Matrix4.translate(Vector3 t)Matrix4Tạo ma trận dịch chuyển
Matrix4.translate(double x, double y, double z)Matrix4Tạo ma trận dịch chuyển từ các thành phần
Matrix4.scale(Vector3 s)Matrix4Tạo ma trận tỉ lệ
Matrix4.scale(double x, double y, double z)Matrix4Tạo ma trận tỉ lệ từ các thành phần
Matrix4.rotateFromQuaternion(Quaternion q)Matrix4Tạo ma trận quay từ quaternion

Properties

import com.aspose.threed.*;

Scene scene = new Scene();
Node node = scene.getRootNode().createChildNode("box");
node.getTransform().setTranslation(1.0, 2.0, 3.0);
node.getTransform().setEulerAngles(0.0, 45.0, 0.0);

// Read the transform matrix
Matrix4 m = node.getTransform().getTransformMatrix();
System.out.println("Translation X: " + m.m03);   // 1.0

// Matrix multiplication
Matrix4 translate = Matrix4.translate(5.0, 0.0, 0.0);
Matrix4 scale = Matrix4.scale(2.0, 2.0, 2.0);
Matrix4 combined = translate.multiply(scale);

// Inverse
Matrix4 inv = m.inverse();

// Transform a point
Vector3 point = new Vector3(1.0, 0.0, 0.0);
Vector3 transformed = m.transformPoint(point);
System.out.println(transformed);

Xem thêm

 Tiếng Việt