Class Matrix4

חבילה: @aspose/3d (v24.12.0)

Matrix4 מאחסן מטריצת שינוי של 4×4 כמערך שטוח של 16 מספרים בסדר שורות. זהו הסוג של Transform.transformMatrix ו GlobalTransform.transformMatrix. אלמנטים בודדים נגישים כ m00m33 תכונות, או באמצעות אינדקס דרך getItem(i) / setItem(i, v). Matrix4 מיוצא מ @aspose/3d/utilities תת‑נתיב.

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

ImageRenderOptions

בנה מטריצת 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

ImageRenderOptions

ImageRenderOptionsImageRenderOptions
new Matrix4()יוצר את מטריצת הזהות בגודל 4×4.
new Matrix4(matrix: number[])יוצר מטריצה ממערך של 16 אלמנטים בסדר שורות.
new Matrix4(...args: number[])יוצר מטריצה מ-16 ארגומנטים מספריים נפרדים.

מאפיינים סטטיים

ImageRenderOptionsImageRenderOptionsImageRenderOptions
Matrix4.identityMatrix4מחזיר מטריצת זהות חדשה.

ImageRenderOptions

ה-16 רכיבי המטריצה נגישים כמאפיינים בשם נפרד m00, m01, m02, m03, m10, …, m33, כאשר הספרה הראשונה היא השורה והשנייה היא העמודה. כולם קריאים וניתנים לכתיבה.

ImageRenderOptionsImageRenderOptionsImageRenderOptions
m00m33numberרכיבי מטריצה בודדים (פריסה לפי שורות).
determinantnumber (קריאה בלבד)הדטרמיננטה הסקלרית של המטריצה.

מתודות סטטיות

Matrix4.translate(v)

יוצר מטריצת תרגום טהורה מ- Vector3, או מ- (tx, ty, tz) מספרים.

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

ImageRenderOptions

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)

יוצר מטריצת קנה מידה טהורה מ- Vector3, או מ- (sx, sy, sz) מספרים.

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

Matrix4.rotate(q)

יוצר מטריצת סיבוב מ- Quaternion, או מזווית (ברדיאנים) וציר Vector3.

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

ImageRenderOptions

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)

יוצר מטריצת rotation מזוויות אוילר ברדיאנים.

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

שיטות מופע

concatenate(m2)

מחזיר את מכפלת המטריצה this × m2. השתמש בזה כדי לשלב טרנספורמציות (החל this קודם, ואז m2).

concatenate(m2: Matrix4): Matrix4

ImageRenderOptions

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

ImageRenderOptions

translation any[] — מערך פלט. לאחר הקריאה, translation[0] הוא אובייקט {x, y, z} עם התרגום.

scaling any[] — מערך פלט. לאחר הקריאה, scaling[0] הוא אובייקט {x, y, z} עם גורמי הקנה.

rotation any[] — מערך פלט. לאחר הקריאה, rotation[0] הוא אובייקט {w, x, y, z} עם רכיבי הקווטרניון של הסיבוב.

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)

מגדיר את המטריצה הזו כמכפלה של תרגום, סיבוב וקנה מידה. הקלטים יכולים להיות אובייקטים פשוטים עם x, y, zw לסיבוב) שדות.

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)

ImageRenderOptions true אם כל 16 האלמנטים שווים בדיוק.

equals(other: Matrix4): boolean
 עברית