Class Matrix4
بسته: @aspose/3d (v24.12.0)
Matrix4 یک ماتریس تبدیل ۴×۴ را بهصورت آرایهای صاف از ۱۶ عدد به ترتیب سطری ذخیره میکند. این نوع Transform.transformMatrix و GlobalTransform.transformMatrix. عناصر تکتک بهصورت … قابل دسترسی هستند m00–m33 ویژگیها، یا بهوسیلهٔ ایندکس از طریق getItem(i) / setItem(i, v). Matrix4 از این صادر میشود @aspose/3d/utilities مسیر فرعی.
export class Matrix4import { 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
| ImageRenderOptions | ImageRenderOptions |
|---|---|
new Matrix4() | ماتریس همانی ۴×۴ را ایجاد میکند. |
new Matrix4(matrix: number[]) | ماتریس را از یک آرایهٔ ۱۶ عنصری به ترتیب سطر‑محور ایجاد میکند. |
new Matrix4(...args: number[]) | ماتریس را از ۱۶ آرگومان عددی جداگانه ایجاد میکند. |
ویژگیهای ایستا
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
Matrix4.identity | Matrix4 | یک ماتریس همانی جدید برمیگرداند. |
ImageRenderOptions
۱۶ عنصر ماتریس بهصورت ویژگیهای نامدار جداگانه قابل دسترسی هستند m00, m01, m02, m03, m10, …, m33,، که رقم اول ردیف و رقم دوم ستون است. همه قابل خواندن و نوشتن هستند.
| ImageRenderOptions | ImageRenderOptions | ImageRenderOptions |
|---|---|---|
m00–m33 | number | عناصر تکتک ماتریس (چیدمان سطر-محور). |
determinant | number (فقطخواندنی) | دترمینان عددی ماتریس. |
متدهای ایستا
Matrix4.translate(v)
یک pure translation matrix از یک Vector3,، یا از مقادیر فردی (tx, ty, tz) اعداد.
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)
یک pure scaling matrix از یک Vector3,، یا از مقادیر فردی (sx, sy, sz) اعداد.
static scale(v: Vector3): Matrix4
static scale(sx: number, sy?: number, sz?: number): Matrix4Matrix4.rotate(q)
یک ماتریس چرخش را از یک Quaternion, یا از یک زاویه (بر حسب رادیان) و یک محور 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)
یک ماتریس چرخش را از زاویههای اویلر بر حسب رادیان ایجاد میکند.
static rotateFromEuler(rx: number, ry?: number, rz?: number): Matrix4
static rotateFromEuler(v: Vector3): Matrix4متدهای نمونه
concatenate(m2)
محصول ماتریس را برمیگرداند this × m2. از این برای ترکیب تبدیلات استفاده کنید (اعمال this اول، سپس 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()
معکوس این ماتریس را برمیگرداند. اگر ماتریس تکین باشد (دترمینان نزدیک به صفر) استثنا میاندازد.
inverse(): Matrix4transpose()
ترانهاده این ماتریس را برمیگرداند (سطرها به ستونها تبدیل میشوند).
transpose(): Matrix4normalize()
یک ماتریس جدید برمیگرداند که زیرماتریس چرخش (۳×۳ بالا‑چپ) آن با تقسیم هر سطر بر طول آن به صورت ارتنرمال شده است. ستون ترجمه حفظ میشود.
normalize(): Matrix4decompose(translation, scaling, rotation)
این ماتریس را به مؤلفههای ترجمه، مقیاس و چرخش تجزیه میکند. نتایج در اولین عنصر هر آرایه خروجی نوشته میشوند.
decompose(translation: any[], scaling: any[], rotation: any[]): voidImageRenderOptions
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, z (و w برای چرخش) فیلدها.
setTRS(translation: any, rotation: any, scale: any): voidtoArray()
یک کپی از آرایه داخلی 16 عنصری به ترتیب row-major برمیگرداند.
toArray(): number[]getItem(index) / setItem(index, value)
دسترسی به عنصر با ایندکس خطی (0–15، ترتیب row-major).
getItem(key: number): number
setItem(key: number, value: number): voidequals(other)
ImageRenderOptions true اگر تمام 16 عنصر بهطور دقیق برابر باشند.
equals(other: Matrix4): boolean