Matrix4
Methods
Matrix4 הוא מטריצה של 4×4 ברמת דיוק כפולה המאוחסנת בסדר שורות עם 16 אלמנטים (m00–m33). זה משמש לחישובי טרנספורמציות עולם/מקומיות, פרוייקציות מותאמות, ופירוק טרנספורמציות של צמתים לתרגום, סיבוב וקנה מידה.
Methods: aspose.threed.utilities
from aspose.threed.utilities import Matrix4Methods
| Methods | Methods |
|---|---|
Matrix4() | מטריצה זהות |
Matrix4(m00, m01, ..., m33) | בונה מפורש של 16 אלמנטים (סדר שורות) |
Matrix4(values) | מבנים מרשימה של 16 float ערכים |
תכונות אלמנטים
אלמנטים נקראים mRC איפה R האם השורה (0–3) ו C הוא העמודה (0–3). לדוגמה, m03 הוא שורה 0, עמודה 3 (התרגום בציר X כאשר המטריצה מקודדת שינוי). כל 16 המאפיינים (m00 דרך m33) קריאים וניתנים לכתיבה.
המערך ניתן לגישה גם באמצעות אינדקס שטוח: mat[0]–mat[15].
תכונות מחושבות
| Methods | Methods | Methods |
|---|---|---|
determinant | float | הדטרמיננטה הסקלרית של המטריצה |
מתודות יצרן סטטיות
| Methods | סוג החזרה | Methods |
|---|---|---|
Matrix4.get_identity() | Matrix4 | מחזיר מטריצה זהות |
Matrix4.translate(tx, ty, tz) | Matrix4 | מטריצת תרגום; מקבלת גם a Vector3 או סקלר יחיד לתרגום אחיד |
Matrix4.scale(sx, sy, sz) | Matrix4 | מטריצת קנה מידה; מקבלת גם a 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 (אוילר), וקנה מידה 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