Class Matrix4

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

Matrix4 speichert eine 4×4 Transformationsmatrix als flaches Array von 16 Zahlen in Zeilen‑Major‑Reihenfolge. Es ist der Typ von Transform.transformMatrix und GlobalTransform.transformMatrix. m00m33 Einzelne Elemente sind zugänglich als getItem(i) / setItem(i, v). Matrix4 Eigenschaften, oder über den Index mittels @aspose/3d/utilities wird aus dem exportiert.

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

Example

Erstelle eine kombinierte TRS-Matrix und zerlege sie wieder in ihre Komponenten.

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

Example

ExampleExample
new Matrix4()Erstellt die 4×4 Einheitsmatrix.
new Matrix4(matrix: number[])Erstellt eine Matrix aus einem 16‑Element‑Array in Zeilen‑Major‑Reihenfolge.
new Matrix4(...args: number[])Erzeugt eine Matrix aus 16 einzelnen Zahlenargumenten.

Statische Eigenschaften

ExampleExampleExample
Matrix4.identityMatrix4Gibt eine neue Einheitsmatrix zurück.

Example

Die 16 Matrix‑Elemente sind als einzelne benannte Eigenschaften zugänglich m00, m01, m02, m03, m10, …, m33, wobei die erste Ziffer die Zeile und die zweite die Spalte ist. Alle sind les‑ und schreibbar.

ExampleExampleExample
m00m33numberEinzelne Matrix‑Elemente (zeilenweise Anordnung).
determinantnumber (nur lesbar)Der skalare Determinantwert der Matrix.

Statische Methoden

Matrix4.translate(v)

Erzeugt eine reine Translationsmatrix aus einem Vector3, oder aus einzelnen (tx, ty, tz) Zahlen.

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

Example

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)

Erzeugt eine reine Skalierungsmatrix aus einem Vector3, oder von einzelnen (sx, sy, sz) Zahlen.

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

Matrix4.rotate(q)

Erstellt eine Rotationsmatrix aus einer Quaternion, oder aus einem Winkel (in Bogenmaß) und einer Achse Vector3.

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

Example

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)

Erstellt eine Rotationsmatrix aus Euler-Winkeln in Radiant.

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

options LoadOptions (optional)

concatenate(m2)

Gibt das Matrixprodukt zurück this × m2. Verwenden Sie dies, um Transformationen zu kombinieren (wenden this zuerst, dann m2).

concatenate(m2: Matrix4): Matrix4

Example

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

Gibt die Inverse dieser Matrix zurück. Wirft eine Ausnahme, wenn die Matrix singulär ist (Determinante nahe Null).

inverse(): Matrix4

transpose()

Gibt die Transponierte dieser Matrix zurück (Zeilen werden zu Spalten).

transpose(): Matrix4

normalize()

Gibt eine neue Matrix zurück, bei der die Rotations‑Untermatrix (oben links 3×3) orthonormiert wird, indem jede Zeile durch ihre Länge geteilt wird. Die Translationsspalte bleibt erhalten.

normalize(): Matrix4

decompose(translation, scaling, rotation)

Zerlegt diese Matrix in Translations-, Skalierungs- und Rotationskomponenten. Die Ergebnisse werden in das erste Element jedes Ausgabearrays geschrieben.

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

Example

translation any[] — Ausgabearray. Nach dem Aufruf, translation[0] ist ein Objekt {x, y, z} mit der Übersetzung.

scaling any[] — Ausgabearray. Nach dem Aufruf, scaling[0] ist ein Objekt {x, y, z} mit den Skalierungsfaktoren.

rotation any[] — Ausgabearray. Nach dem Aufruf, rotation[0] ist ein Objekt {w, x, y, z} mit den Rotationsquaternion‑Komponenten.

Example

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)

Setzt diese Matrix auf das Produkt aus Translation, Rotation und Skalierung. Die Eingaben können einfache Objekte mit x, y, z (und w für Rotation) Felder.

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

toArray()

Gibt eine Kopie des internen 16‑Elemente‑zeilenweise‑geordneten Arrays zurück.

toArray(): number[]

getItem(index) / setItem(index, value)

Elementzugriff über linearen Index (0–15, zeilenweise Reihenfolge).

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

equals(other)

Example true wenn alle 16 Elemente streng gleich sind.

equals(other: Matrix4): boolean
 Deutsch