Matrix4 — Aspose.3D FOSS for Java

Example

Matrix4 是一个用于 3D 空间仿射变换的 4x4 双精度矩阵。它由以下函数返回: Transform.getTransformMatrix()GlobalTransform.getTransformMatrix(),,并且可以通过平移、旋转和缩放(TRS)分解来构造。.

Example: com.aspose.threed

import com.aspose.threed.*;

Example

ExampleExample
Matrix4()构造一个单位矩阵
Matrix4(double m00, double m01, ... double m33)由 16 个单独元素构成(行主序)

静态字段

ExampleExampleExample
IDENTITYMatrix44x4 单位矩阵

公共字段(元素访问)

Matrix4 使用 公共字段 用于元素访问:: m00, m01, … m33 (共 16 个字段,行主序布局)。.

字段模式ExampleExample
m00m33double将矩阵的各个元素作为公共字段。访问方式为 mat.m00, mat.m01,,等。.

翻译组件位于最后一列:: m03 (X), m13 (Y), m23 (Z).

Example

Example返回类型Example
multiply(Matrix4 other)Matrix4矩阵乘法;返回一个新矩阵
inverse()Matrix4返回逆矩阵
transpose()Matrix4返回转置矩阵
decompose(Vector3 translation, Vector3 scaling, Quaternion rotation)boolean存根:: 始终返回 false. 旨在将矩阵分解为 TRS 组件,但尚未实现。.
determinant()double返回矩阵的行列式
transformPoint(Vector3 point)Vector3变换一个点(应用完整的平移 + 旋转 + 缩放)
transformDirection(Vector3 direction)Vector3变换方向向量(应用旋转 + 缩放,忽略平移)

静态方法

Example返回类型Example
Matrix4.translate(Vector3 t)Matrix4创建平移矩阵
Matrix4.translate(double x, double y, double z)Matrix4从组件创建平移矩阵
Matrix4.scale(Vector3 s)Matrix4创建缩放矩阵
Matrix4.scale(double x, double y, double z)Matrix4从组件创建缩放矩阵
Matrix4.rotateFromQuaternion(Quaternion q)Matrix4从四元数创建旋转矩阵

Example

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);

另见

 中文