Matrix4
Methods
Matrix4 เป็นเมทริกซ์ double-precision 4×4 ที่จัดเก็บใน row-major order โดยมี 16 องค์ประกอบ (m00–m33). ใช้สำหรับการคำนวณการแปลงแบบ world/local, การฉายภาพแบบกำหนดเอง, และการแยกการแปลงของโหนดเป็นการแปล, การหมุน, และการสเกล.
Methods: aspose.threed.utilities
from aspose.threed.utilities import Matrix4Methods
| Methods | Methods |
|---|---|
Matrix4() | เมทริกซ์เอกลักษณ์ |
Matrix4(m00, m01, ..., m33) | คอนสตรัคเตอร์ 16‑element แบบชัดเจน (ลำดับแถว‑หลัก) |
Matrix4(values) | โครงสร้างจากรายการ 16 float ค่า |
คุณสมบัติขององค์ประกอบ
องค์ประกอบมีชื่อ mRC ที่ไหน R คือแถว (0–3) และ C คือคอลัมน์ (0–3) ตัวอย่างเช่น, m03 เป็นแถวที่ 0, คอลัมน์ที่ 3 (การแปลตำแหน่ง X เมื่อเมทริกซ์เข้ารหัสการแปลง)m00 ผ่าน m33) สามารถอ่านและเขียนได้.
เมทริกซ์ยังสามารถเข้าถึงได้โดยใช้ดัชนีแบบแบน: mat[0]–mat[15].
คุณสมบัติที่คำนวณ
| Methods | Methods | Methods |
|---|---|---|
determinant | float | ดีเทอร์มิแนนต์สเกลาร์ของเมทริกซ์ |
เมธอดแฟกทอรีแบบสแตติก
| Methods | ประเภทการคืนค่า | Methods |
|---|---|---|
Matrix4.get_identity() | Matrix4 | คืนเมทริกซ์เอกลักษณ์ |
Matrix4.translate(tx, ty, tz) | Matrix4 | เมทริกซ์การแปล; ยังรับค่า Vector3 หรือสเกลาร์เดียวสำหรับการแปลแบบสม่ำเสมอ |
Matrix4.scale(sx, sy, sz) | Matrix4 | เมทริกซ์สเกล; ยังรับค่า Vector3 หรือสเกลาร์ตัวเดียวสำหรับสเกลแบบสม่ำเสมอ |
Matrix4.rotate(angle, axis) | Matrix4 | เมทริกซ์การหมุนจากมุม (เรเดียน) และ Vector3 แกน; ยังรับค่า Quaternion เป็นอาร์กิวเมนต์เดียว |
Matrix4.rotate_from_euler(rx, ry, rz) | Matrix4 | เมทริกซ์การหมุนจากมุมออยเลอร์ (เรเดียน); ยังรับค่า Vector3 |
เมธอดอินสแตนซ์
| Methods | ประเภทการคืนค่า | Methods |
|---|---|---|
concatenate(m2) | Matrix4 | คืนผลคูณของเมทริกซ์ self × m2 |
normalize() | Matrix4 | คืนสำเนาที่มีแกนการหมุนทำการออร์โธนอร์มัลใหม่ (ลบสเกลออกจากคอลัมน์การหมุน) |
transpose() | Matrix4 | คืนเมทริกซ์ที่ทำการทรานสโพส |
inverse() | Matrix4 | คืนเมทริกซ์ผกผัน; ยกข้อยกเว้น ValueError ถ้าเมทริกซ์เป็นเอกฐาน |
decompose(translation, scaling, rotation) | None | แยกเป็นส่วนประกอบ TRS ผลลัพธ์จะถูกเขียนลงในรายการที่มีเพียงหนึ่งองค์ประกอบ: translation[0] → Vector3, scaling[0] → Vector3, rotation[0] → Quaternion |
set_trs(translation, rotation, scale) | None | ตั้งค่าเมทริกซ์ในที่เดิมจากการแปลงตำแหน่ง Vector3, การหมุน Quaternion หรือ Vector3 (Euler), และสเกล Vector3 |
to_array() | list[float] | คืนค่า 16 องค์ประกอบเป็นรายการแบน |
Methods
from aspose.threed.utilities import Matrix4, Vector3, Quaternion
import math
# Build a transform: translate (5, 0, 0), rotate 90 deg around Y, scale 2x
t = Matrix4.translate(5.0, 0.0, 0.0)
r = Matrix4.rotate(math.radians(90), Vector3(0, 1, 0))
s = Matrix4.scale(2.0, 2.0, 2.0)
# Combine: scale first, then rotate, then translate
combined = t.concatenate(r.concatenate(s))
# Decompose the result back into TRS
translation = [None]
scaling = [None]
rotation = [None]
combined.decompose(translation, scaling, rotation)
print(translation[0]) # Vector3(5.0, 0.0, 0.0)
print(scaling[0]) # Vector3(2.0, 2.0, 2.0)
# Retrieve from a node's global transform
from aspose.threed import Scene
scene = Scene()
node = scene.root_node.create_child_node("box")
node.transform.translation = Vector3(10.0, 0.0, 0.0)
world_mat = node.global_transform.transform_matrix
print(world_mat.m03) # 10.0 — translation X