Class Matrix4

แพคเกจ: @aspose/3d (v24.12.0)

Matrix4 เก็บเมทริกซ์การแปลง 4×4 เป็นอาเรย์แบนของ 16 ตัวเลขในลำดับ row-major. มันเป็นประเภทของ Transform.transformMatrix และ GlobalTransform.transformMatrix. สามารถเข้าถึงองค์ประกอบแต่ละตัวได้เป็น m00m33 คุณสมบัติ, หรือโดยใช้ดัชนีผ่าน getItem(i) / setItem(i, v). Matrix4 ถูกส่งออกจาก @aspose/3d/utilities เส้นทางย่อย.

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

Properties

สร้างเมทริกซ์ 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

Properties

PropertiesProperties
new Matrix4()สร้างเมทริกซ์เอกลักษณ์ 4×4.
new Matrix4(matrix: number[])สร้างเมทริกซ์จากอาเรย์ 16-องค์ประกอบในลำดับ row-major.
new Matrix4(...args: number[])สร้างเมทริกซ์จากอาร์กิวเมนต์ตัวเลข 16 ตัวแยกกัน.

คุณสมบัติสถิต

PropertiesPropertiesProperties
Matrix4.identityMatrix4คืนค่าเมทริกซ์เอกลักษณ์ใหม่.

Properties

องค์ประกอบเมทริกซ์ 16 ตัวสามารถเข้าถึงได้เป็นคุณสมบัติที่มีชื่อแยกแต่ละตัว m00, m01, m02, m03, m10, …, m33, โดยที่ตัวเลขตัวแรกคือแถวและตัวที่สองคือคอลัมน์ ทั้งหมดสามารถอ่านและเขียนได้.

PropertiesPropertiesProperties
m00m33numberองค์ประกอบเมทริกซ์แยกแต่ละตัว (การจัดเรียงแบบ row-major).
determinantnumber (อ่านอย่างเดียว)ดีเทอร์มิแนนต์สเกลาร์ของเมทริกซ์.

เมธอดสถิตย์

Matrix4.translate(v)

สร้างเมทริกซ์การแปลที่บริสุทธิ์จาก a Vector3, หรือจากแต่ละ (tx, ty, tz) ตัวเลข.

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

Properties

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

Properties

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): Matrix4

Properties

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 ด้านบนซ้าย) ทำให้เป็นออร์โธโนมัลโดยการหารแต่ละแถวด้วยความยาวของมัน. คอลัมน์การแปล (translation) จะถูกเก็บไว้.

normalize(): Matrix4

decompose(translation, scaling, rotation)

แยกเมทริกซ์นี้ออกเป็นส่วนประกอบของการแปล, การสเกล, และการหมุน. ผลลัพธ์จะถูกเขียนลงในองค์ประกอบแรกของแต่ละอาร์เรย์ผลลัพธ์.

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

Properties

translation any[] — อาร์เรย์ผลลัพธ์ หลังจากเรียกใช้, translation[0] เป็นอ็อบเจกต์ {x, y, z} ที่มีการแปลตำแหน่ง.

scaling any[] — อาร์เรย์ผลลัพธ์ หลังจากเรียกใช้, scaling[0] เป็นอ็อบเจกต์ {x, y, z} ที่มีปัจจัยสเกล.

rotation any[] — อาร์เรย์ผลลัพธ์ หลังจากเรียกใช้, rotation[0] เป็นวัตถุ {w, x, y, z} พร้อมกับส่วนประกอบของ quaternion การหมุน.

Properties

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): void

toArray()

คืนสำเนาของอาร์เรย์ภายในที่มี 16 องค์ประกอบแบบ row-major.

toArray(): number[]

getItem(index) / setItem(index, value)

การเข้าถึงองค์ประกอบโดยดัชนีเชิงเส้น (0–15, ลำดับแถวหลัก).

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

equals(other)

Properties true หากทุก 16 องค์ประกอบเท่ากันอย่างเคร่งครัด.

equals(other: Matrix4): boolean
 ภาษาไทย