Class Matrix4
Csomag: @aspose/3d (v24.12.0)
Matrix4 tárol egy 4×4-es transzformációs mátrixot egy lapos, 16 számot tartalmazó tömbként sor-major sorrendben. Ez a típusa Transform.transformMatrix és GlobalTransform.transformMatrix. Az egyes elemek elérhetők mint m00–m33 tulajdonságokként, vagy index szerint a getItem(i) / setItem(i, v). Matrix4 exportálva van a @aspose/3d/utilities alútvonal.
export class Matrix4import { Matrix4 } from '@aspose/3d/utilities';ImageRenderOptions
Építs egy kombinált TRS mátrixot, és bontsd le újra alkotóelemeire.
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
| ImageRenderOptions | ImageRenderOptions |
|---|---|
new Matrix4() | Létrehozza a 4×4-es egységmátrixot. |
new Matrix4(matrix: number[]) | Létrehoz egy mátrixot egy 16 elemből álló tömbből sor-major sorrendben. |
new Matrix4(...args: number[]) | Létrehoz egy mátrixot 16 különálló szám argumentumból. |
Statikus tulajdonságok
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
Matrix4.identity | Matrix4 | Visszaad egy új egységmátrixot. |
ImageRenderOptions
A 16 mátrixelem egyedi névvel ellátott tulajdonságként érhető el m00, m01, m02, m03, m10, …, m33, ahol az első számjegy a sor, a második az oszlop. Mindegyik olvasható és írható.
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
m00–m33 | number | Az egyes mátrixelemek (sor-major elrendezés). |
determinant | number (csak olvasható) | A mátrix skaláris determinánsa. |
Statikus metódusok
Matrix4.translate(v)
Létrehoz egy tiszta transzlációs mátrixot egy Vector3, vagy egyedi (tx, ty, tz) számok.
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)
Létrehoz egy tiszta skálázási mátrixot egy Vector3, vagy egyedi (sx, sy, sz) számokból.
static scale(v: Vector3): Matrix4
static scale(sx: number, sy?: number, sz?: number): Matrix4Matrix4.rotate(q)
Létrehoz egy forgatási mátrixot egy Quaternion, vagy egy szögből (radiánban) és egy tengelyből 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)
Forgatási mátrixot hoz létre Euler-szögekből radiánban.
static rotateFromEuler(rx: number, ry?: number, rz?: number): Matrix4
static rotateFromEuler(v: Vector3): Matrix4Példánymetódusok
concatenate(m2)
Visszaadja a mátrix szorzatát this × m2. Használd ezt a transzformációk kombinálásához (alkalmazd this először, majd 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()
Visszaadja ennek a mátrixnak az inverzét. Kivételt dob, ha a mátrix szinguláris (determináns közel nulla).
inverse(): Matrix4transpose()
Visszaadja ennek a mátrixnak a transzponáltját (a sorok oszlopokká válnak).
transpose(): Matrix4normalize()
Visszaad egy új mátrixot, amelynek a forgatási (bal felső 3×3) almátrixa ortonormálissá van téve úgy, hogy minden sort a hosszával osztunk. A transzlációs oszlop megmarad.
normalize(): Matrix4decompose(translation, scaling, rotation)
Feltöri ezt a mátrixot transzlációra, skálázásra és forgatásra. Az eredményeket az egyes kimeneti tömbök első elemébe írja.
decompose(translation: any[], scaling: any[], rotation: any[]): voidImageRenderOptions
translation any[] — Kimeneti tömb. A hívás után, translation[0] egy objektum {x, y, z} a transzlációval.
scaling any[] — Kimeneti tömb. A hívás után, scaling[0] egy objektum {x, y, z} a skálázási tényezőkkel.
rotation any[] — Kimeneti tömb. A hívás után, rotation[0] egy objektum {w, x, y, z} a forgatási kvaternió komponenseivel.
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)
Beállítja ezt a mátrixot egy eltolás, forgatás és méretezés szorzataként. A bemenetek lehetnek egyszerű objektumok a következőkkel x, y, z (és w a forgatáshoz) mezőket.
setTRS(translation: any, rotation: any, scale: any): voidtoArray()
Visszaad egy másolatot a belső 16 elemes sor-major tömbről.
toArray(): number[]getItem(index) / setItem(index, value)
Elem elérése lineáris index alapján (0–15, sor-major sorrendben).
getItem(key: number): number
setItem(key: number, value: number): voidequals(other)
ImageRenderOptions true ha minden 16 elem szigorúan egyenlő.
equals(other: Matrix4): boolean