Matrix4

Gói: @aspose/3d (v24.12.0)

Matrix4 lưu trữ một ma trận biến đổi 4×4 dưới dạng một mảng phẳng gồm 16 số theo thứ tự hàng. Đây là kiểu của Transform.transformMatrixGlobalTransform.transformMatrix. Các phần tử riêng lẻ có thể truy cập dưới dạng m00m33 các thuộc tính, hoặc bằng chỉ mục qua getItem(i) / setItem(i, v). Matrix4 được xuất khẩu từ @aspose/3d/utilities đường dẫn phụ.

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

Enumerations

Xây dựng một ma trận TRS kết hợp và phân tách lại nó thành các thành phần.

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

Enumerations

NameTypeAccessDescription
m00numberRead/WriteGets the m00.
m01numberRead/WriteGets the m01.
m02numberRead/WriteGets the m02.
m03numberRead/WriteGets the m03.
m10numberRead/WriteGets the m10.
m11numberRead/WriteGets the m11.
m12numberRead/WriteGets the m12.
m13numberRead/WriteGets the m13.
m20numberRead/WriteGets the m20.
m21numberRead/WriteGets the m21.
m22numberRead/WriteGets the m22.
m23numberRead/WriteGets the m23.
m30numberRead/WriteGets the m30.
m31numberRead/WriteGets the m31.
m32numberRead/WriteGets the m32.
m33numberRead/WriteGets the m33.
determinantnumberReadGets the determinant.

Thuộc tính tĩnh

SignatureDescription
constructor()Creates a new 4x4 matrix, optionally from a 16‑element number array
constructor(matrix: number[])
constructor()
constructor()
getItem(key: number)numberReturns the matrix element at the given linear index
setItem(key: number, value: number)Sets the item value.
transpose()Matrix4Returns a new Matrix4 that is the transpose of this matrix
concatenate(m2: Matrix4)Matrix4
normalize()Matrix4Returns a new Matrix4 with uniform scaling removed (unit length axes)
inverse()Matrix4
decompose(translation: any[], scaling: any[], rotation: any[])Extracts translation, scaling, and rotation into the supplied arrays
setTRS(translation: any, rotation: any, scale: any)Sets the trs value.
toArray()number[]Returns the matrix elements as a 16‑length number array in row‑major order
identity()Matrix4Resets the matrix to the identity matrix and returns this instance
translate(tx: number, ty: number, tz: number)Matrix4Applies a translation by (tx,ty,tz) or a vector and returns this matrix
translate(v: any)Matrix4
translate(tx: any, ty: any, tz: any)Matrix4
scale(sx: number, sy: number, sz: number)Matrix4Applies scaling by (sx,sy,sz) or a vector and returns this matrix
scale(v: any)Matrix4
scale(sx: any, sy: any, sz: any)Matrix4
rotateFromEuler(rx: number, ry: number, rz: number)Matrix4
rotateFromEuler(v: any)Matrix4
rotateFromEuler(rx: any, ry: any, rz: any)Matrix4
rotate(angle: number, axis: any)Matrix4Creates a rotation matrix from an angle and axis or from a quaternion
rotate(q: Quaternion)Matrix4
rotate(angle: any, axis: any)Matrix4
toString()stringReturns a human‑readable string representation of the matrix values
equals(other: Matrix4)booleanCompares this matrix with another for element‑wise equality

Enumerations

16 phần tử của ma trận có thể truy cập dưới dạng các thuộc tính có tên riêng lẻ m00, m01, m02, m03, m10, …, m33, trong đó chữ số đầu tiên là hàng và chữ số thứ hai là cột. Tất cả đều có thể đọc và ghi.

EnumerationsEnumerationsEnumerations
m00m33numberCác phần tử ma trận riêng lẻ (bố cục theo hàng).
determinantnumber (chỉ đọc)Định thức vô hướng của ma trận.

Phương thức tĩnh

Matrix4.translate(v)

Tạo một ma trận dịch chuyển thuần túy từ một Vector3, hoặc từ các cá nhân (tx, ty, tz) các số.

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

Enumerations

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)

Tạo ma trận tỉ lệ thuần túy từ một Vector3, hoặc từ các (sx, sy, sz) số.

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

Matrix4.rotate(q)

Tạo ma trận quay từ một Quaternion, hoặc từ một góc (đơn vị radian) và một trục Vector3.

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

Enumerations

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)

Tạo một ma trận quay từ các góc Euler tính bằng radian.

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

Phương thức đối tượng

concatenate(m2)

Trả về tích ma trận this × m2. Sử dụng điều này để kết hợp các biến đổi (áp dụng this đầu tiên, sau đó m2).

concatenate(m2: Matrix4): Matrix4

Enumerations

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

Trả về ma trận nghịch đảo của ma trận này. Ném ngoại lệ nếu ma trận là singular (định thức gần bằng zero).

inverse(): Matrix4

transpose()

Trả về ma trận chuyển vị của ma trận này (các hàng trở thành cột).

transpose(): Matrix4

normalize()

Trả về một ma trận mới với phần ma trận con xoay (3×3 ở góc trên‑trái) được chuẩn hoá trực giao bằng cách chia mỗi hàng cho độ dài của nó. Cột dịch chuyển được giữ nguyên.

normalize(): Matrix4

decompose(translation, scaling, rotation)

Phân tách ma trận này thành các thành phần dịch chuyển, tỉ lệ và xoay. Kết quả được ghi vào phần tử đầu tiên của mỗi mảng đầu ra.

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

Enumerations

translation any[] — Mảng đầu ra. Sau khi gọi, translation[0] là một đối tượng {x, y, z} với phép dịch chuyển.

scaling any[] — Mảng đầu ra. Sau khi gọi, scaling[0] là một đối tượng {x, y, z} với các hệ số tỉ lệ.

rotation any[] — Mảng đầu ra. Sau khi gọi, rotation[0] là một đối tượng {w, x, y, z} với các thành phần quaternion quay.

Enumerations

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)

Đặt ma trận này thành tích của một phép dịch, quay và tỉ lệ. Các đầu vào có thể là các đối tượng đơn giản với x, y, z (và w cho quay) các trường.

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

toArray()

Trả về một bản sao của mảng nội bộ 16 phần tử theo thứ tự hàng.

toArray(): number[]

getItem(index) / setItem(index, value)

Truy cập phần tử theo chỉ mục tuyến tính (0–15, theo thứ tự hàng).

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

equals(other)

Enumerations true nếu tất cả 16 phần tử đều hoàn toàn bằng nhau.

equals(other: Matrix4): boolean
 Tiếng Việt