Matrix4
Paketas: @aspose/3d (v24.12.0)
Matrix4 saugo 4×4 transformacijos matricą kaip plokščią 16 skaičių masyvą eilutės tvarka. Tai yra tipo Transform.transformMatrix ir GlobalTransform.transformMatrix. Individualūs elementai yra prieinami kaip m00–m33 savybės, arba pagal indeksą per getItem(i) / setItem(i, v). Matrix4 yra eksportuojamas iš @aspose/3d/utilities subkelio.
export class Matrix4import { Matrix4 } from '@aspose/3d/utilities';ImageRenderOptions
Sukurkite sujungtą TRS matricą ir dekomponuokite ją atgal į komponentus.
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
ImageRenderOptions
| Name | Type | Access | Description |
|---|---|---|---|
m00 | number | Read/Write | Gets the m00. |
m01 | number | Read/Write | Gets the m01. |
m02 | number | Read/Write | Gets the m02. |
m03 | number | Read/Write | Gets the m03. |
m10 | number | Read/Write | Gets the m10. |
m11 | number | Read/Write | Gets the m11. |
m12 | number | Read/Write | Gets the m12. |
m13 | number | Read/Write | Gets the m13. |
m20 | number | Read/Write | Gets the m20. |
m21 | number | Read/Write | Gets the m21. |
m22 | number | Read/Write | Gets the m22. |
m23 | number | Read/Write | Gets the m23. |
m30 | number | Read/Write | Gets the m30. |
m31 | number | Read/Write | Gets the m31. |
m32 | number | Read/Write | Gets the m32. |
m33 | number | Read/Write | Gets the m33. |
determinant | number | Read | Gets the determinant. |
Statinės savybės
| Signature | Description |
|---|---|
constructor() | Creates a new 4x4 matrix, optionally from a 16‑element number array |
constructor(matrix: number[]) | |
constructor() | |
constructor() | |
getItem(key: number) → number | Returns the matrix element at the given linear index |
setItem(key: number, value: number) | Sets the item value. |
transpose() → Matrix4 | Returns a new Matrix4 that is the transpose of this matrix |
concatenate(m2: Matrix4) → Matrix4 | |
normalize() → Matrix4 | Returns 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() → Matrix4 | Resets the matrix to the identity matrix and returns this instance |
translate(tx: number, ty: number, tz: number) → Matrix4 | Applies 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) → Matrix4 | Applies 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) → Matrix4 | Creates a rotation matrix from an angle and axis or from a quaternion |
rotate(q: Quaternion) → Matrix4 | |
rotate(angle: any, axis: any) → Matrix4 | |
toString() → string | Returns a human‑readable string representation of the matrix values |
equals(other: Matrix4) → boolean | Compares this matrix with another for element‑wise equality |
ImageRenderOptions
16 matricos elementų galima pasiekti kaip atskiras pavadintas savybes m00, m01, m02, m03, m10, …, m33, kur pirmas skaitmuo nurodo eilutę, o antras – stulpelį. Visi yra skaitomi ir rašomi.
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
m00–m33 | number | Individualūs matricos elementai (eilučių tvarka). |
determinant | number (tik skaitymui) | Matricos skaliarinė determinantas. |
Statiniai metodai
Matrix4.translate(v)
Sukuria grynąją perkėlimo matricą iš a Vector3, arba iš atskirų (tx, ty, tz) skaičiai.
static translate(v: Vector3): Matrix4
static translate(tx: number, ty?: number, tz?: number): Matrix4ImageRenderOptions
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)
Sukuria gryną mastelio matricą iš Vector3, arba iš atskirų (sx, sy, sz) skaičių.
static scale(v: Vector3): Matrix4
static scale(sx: number, sy?: number, sz?: number): Matrix4Matrix4.rotate(q)
Sukuria sukimosi matricą iš Quaternion, arba iš kampo (radijais) ir ašies Vector3.
static rotate(q: Quaternion): Matrix4
static rotate(angle: number, axis: Vector3): Matrix4ImageRenderOptions
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)
Sukuria sukimo matricą iš Eulerio kampų radijais.
static rotateFromEuler(rx: number, ry?: number, rz?: number): Matrix4
static rotateFromEuler(v: Vector3): Matrix4Egzemplioriaus metodai
concatenate(m2)
Grąžina matricos sandaugą this × m2. Naudokite tai transformacijų kombinavimui (taikykite this pirmiausia, tada m2).
concatenate(m2: Matrix4): Matrix4ImageRenderOptions
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()
Grąžina šios matricos inversą. Išmeta išimtį, jei matrica yra singuliari (determinantas artimas nuliui).
inverse(): Matrix4transpose()
Grąžina šios matricos transponuotą (eilučių tampa stulpeliai).
transpose(): Matrix4normalize()
Grąžina naują matricą, kurioje sukimo (viršutinėje kairėje 3×3) po‑matrica ortonormalizuota padalijus kiekvieną eilutę iš jos ilgio. Vertimo stulpelis išsaugomas.
normalize(): Matrix4decompose(translation, scaling, rotation)
Išskaido šią matricą į vertimo, mastelio ir sukimo komponentus. Rezultatai įrašomi į pirmąjį kiekvieno išvesties masyvo elementą.
decompose(translation: any[], scaling: any[], rotation: any[]): voidImageRenderOptions
translation any[] — Išvesties masyvas. Po kvietimo, translation[0] yra objektas {x, y, z} su perkėlimu.
scaling any[] — Išvesties masyvas. Po kvietimo, scaling[0] yra objektas {x, y, z} su mastelio koeficientais.
rotation any[] — Išvesties masyvas. Po kvietimo, rotation[0] yra objektas {w, x, y, z} su sukimosi kvaterniono komponentais.
ImageRenderOptions
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)
Nustato šią matricą į vertimo, sukimo ir mastelio sandaugą. Įvestys gali būti paprasti objektai su x, y, z (ir w pasukimui) laukai.
setTRS(translation: any, rotation: any, scale: any): voidtoArray()
Grąžina vidinės 16 elementų eilutės pagrindo masyvo kopiją.
toArray(): number[]getItem(index) / setItem(index, value)
Elemento prieiga pagal linijinį indeksą (0–15, eilutės pagrindine tvarka).
getItem(key: number): number
setItem(key: number, value: number): voidequals(other)
ImageRenderOptions true jei visi 16 elementai yra griežtai lygūs.
equals(other: Matrix4): boolean