Class Matrix4

Class Matrix4

包:: @aspose/3d (v24.12.0)

Matrix4 将 4×4 变换矩阵存储为按行主序的 16 个数字的一维数组。它是以下类型的 Transform.transformMatrixGlobalTransform.transformMatrix.。单个元素可以通过 m00m33 属性,或通过索引访问 getItem(i) / setItem(i, v). Matrix4 从以下位置导出 @aspose/3d/utilities 子路径。.

export class Matrix4
import { Matrix4 } from '@aspose/3d/utilities';

Properties

构建一个组合的 TRS 矩阵并将其分解回各组件。.

import { Matrix4, Vector3, Quaternion } from '@aspose/3d/utilities';

const t = Matrix4.translate(new Vector3(5, 0, 0));
const r = Matrix4.rotate(Quaternion.fromEulerAngle(0, Math.PI / 4, 0));
const s = Matrix4.scale(new Vector3(2, 2, 2));

const trs = t.concatenate(r).concatenate(s);

const translation: any[] = [null];
const scaling: any[] = [null];
const rotation: any[] = [null];
trs.decompose(translation, scaling, rotation);

console.log(`Translation X: ${translation[0].x}`); // Translation X: 5
console.log(`Scale X: ${scaling[0].x.toFixed(4)}`); // Scale X: 2.0000

Properties

PropertiesProperties
new Matrix4()创建 4×4 单位矩阵。.
new Matrix4(matrix: number[])从按行主序的 16 元素数组创建矩阵。.
new Matrix4(...args: number[])从 16 个单独的数字参数创建矩阵。.

静态属性

PropertiesPropertiesProperties
Matrix4.identityMatrix4返回一个新的单位矩阵。.

Properties

这 16 个矩阵元素可作为单独的具名属性访问 m00, m01, m02, m03, m10, …, m33,,其中第一位数字表示行,第二位数字表示列。所有属性均可读写。.

PropertiesPropertiesProperties
m00m33number单个矩阵元素(行主序布局)。.
determinantnumber (只读)矩阵的标量行列式。.

静态方法

Matrix4.translate(v)

从 a 创建一个纯平移矩阵 Vector3,,或从单个 (tx, ty, tz) 数字。.

static translate(v: Vector3): Matrix4
static translate(tx: number, ty?: number, tz?: number): Matrix4

Properties

import { Matrix4, Vector3 } from '@aspose/3d/utilities';

const m = Matrix4.translate(new Vector3(3, 0, 0));
console.log(`m03: ${m.m03}`); // m03: 3

Matrix4.scale(v)

从 a 创建一个纯缩放矩阵 Vector3,,或从单个 (sx, sy, sz) 数字。.

static scale(v: Vector3): Matrix4
static scale(sx: number, sy?: number, sz?: number): Matrix4

Matrix4.rotate(q)

从 a 创建一个旋转矩阵 Quaternion,,或从一个角度(以弧度为单位)和一个轴 Vector3.

static rotate(q: Quaternion): Matrix4
static rotate(angle: number, axis: Vector3): Matrix4

Properties

import { Matrix4, Quaternion } from '@aspose/3d/utilities';

const q = Quaternion.fromEulerAngle(0, Math.PI / 2, 0);
const m = Matrix4.rotate(q);
console.log(`Rotation matrix m00: ${m.m00.toFixed(4)}`);
// Rotation matrix m00: 0.0000

Matrix4.rotateFromEuler(rx, ry, rz)

从弧度制的欧拉角创建旋转矩阵。.

static rotateFromEuler(rx: number, ry?: number, rz?: number): Matrix4
static rotateFromEuler(v: Vector3): Matrix4

实例方法

concatenate(m2)

返回矩阵乘积 this × m2. 使用此来组合转换(先应用 this 首先,然后 m2).

concatenate(m2: Matrix4): Matrix4

Properties

import { Matrix4, Vector3 } from '@aspose/3d/utilities';

const translate = Matrix4.translate(new Vector3(1, 0, 0));
const scale = Matrix4.scale(new Vector3(2, 2, 2));
const combined = translate.concatenate(scale);
console.log(`m03: ${combined.m03}`); // m03: 1

inverse()

返回此矩阵的逆。如果矩阵是奇异的(行列式接近零),则抛出异常。.

inverse(): Matrix4

transpose()

返回此矩阵的转置(行变为列)。.

transpose(): Matrix4

normalize()

返回一个新矩阵,其中通过将每行除以其长度来对旋转(左上角 3×3)子矩阵进行正交归一化。平移列保持不变。.

normalize(): Matrix4

decompose(translation, scaling, rotation)

将此矩阵分解为平移、缩放和旋转分量。结果写入每个输出数组的第一个元素。.

decompose(translation: any[], scaling: any[], rotation: any[]): void

Properties

translation any[] — 输出数组。调用后,, translation[0] 是一个对象 {x, y, z} 带有翻译。.

scaling any[] — 输出数组。调用后,, scaling[0] 是一个对象 {x, y, z} 带有缩放因子。.

rotation any[] — 输出数组。调用之后,, rotation[0] 是一个对象 {w, x, y, z} 带有旋转四元数分量。.

Properties

import { Matrix4, Vector3, Quaternion } from '@aspose/3d/utilities';

const m = Matrix4.translate(new Vector3(0, 5, 0));
const trans: any[] = [null], scale: any[] = [null], rot: any[] = [null];
m.decompose(trans, scale, rot);
console.log(`Y: ${trans[0].y}`); // Y: 5

setTRS(translation, rotation, scale)

将此矩阵设置为平移、旋转和缩放的乘积。输入可以是带有 x, y, z (以及 w 用于旋转) 字段。.

setTRS(translation: any, rotation: any, scale: any): void

toArray()

返回内部 16 元素行主序数组的副本。.

toArray(): number[]

getItem(index) / setItem(index, value)

通过线性索引访问元素(0–15,行主序)。.

getItem(key: number): number
setItem(key: number, value: number): void

equals(other)

Properties true 如果所有 16 个元素严格相等。.

equals(other: Matrix4): boolean
 中文