Matrix4
Methods
Matrix4 egy 4×4 dupla pontosságú mátrix, sor-major sorrendben tárolva 16 elemmel (m00–m33).
Methods: aspose.threed.utilities
from aspose.threed.utilities import Matrix4Methods
| Methods | Methods |
|---|---|
Matrix4() | Identitásmátrix |
Matrix4(m00, m01, ..., m33) | Explicit 16 elemes konstruktor (sor-major sorrend) |
Matrix4(values) | Létrehozza egy 16 elemből álló listából float értékek |
Elem tulajdonságok
Az elemek nevei mRC ahol R a sor (0–3), és C az oszlop (0–3). Például, m03 sor 0, oszlop 3 (az X eltolás, amikor a mátrix egy transzformációt kódol). Az összes 16 tulajdonság (m00 keresztül m33) olvasható és írható.
A mátrixot lapos index segítségével is el lehet érni: mat[0]–mat[15].
Számított tulajdonságok
| Methods | Methods | Methods |
|---|---|---|
determinant | float | A mátrix skalár determinánsa |
Statikus gyári metódusok
| Methods | Visszatérési típus | Methods |
|---|---|---|
Matrix4.get_identity() | Matrix4 | Visszaad egy egységmátrixot |
Matrix4.translate(tx, ty, tz) | Matrix4 | Transzlációs mátrix; egyet is elfogad Vector3 vagy egyetlen skalárt az egységes transzlációhoz |
Matrix4.scale(sx, sy, sz) | Matrix4 | Skálázó mátrix; egyet is elfogad Vector3 vagy egyetlen skalár az egyenletes skálához |
Matrix4.rotate(angle, axis) | Matrix4 | Forgatási mátrix szögtől (radián) és Vector3 tengely; elfogad egy Quaternion mint egyetlen argumentum |
Matrix4.rotate_from_euler(rx, ry, rz) | Matrix4 | Forgatási mátrix Euler-szögekből (radián); elfogad egy Vector3 |
Példánymetódusok
| Methods | Visszatérési típus | Methods |
|---|---|---|
concatenate(m2) | Matrix4 | Visszaadja a mátrix szorzatot self × m2 |
normalize() | Matrix4 | Visszaad egy másolatot, amelyben a forgatási tengelyek újra ortonormálva vannak (skála eltávolítva a forgatási oszlopokból) |
transpose() | Matrix4 | Visszaadja a transzponált mátrixot |
inverse() | Matrix4 | Visszaadja az inverzét; kivételt dob ValueError ha a mátrix szinguláris |
decompose(translation, scaling, rotation) | None | TRS komponensekre bontja. Az eredmények egyelemes listákba íródnak: translation[0] → Vector3, scaling[0] → Vector3, rotation[0] → Quaternion |
set_trs(translation, rotation, scale) | None | Beállítja a mátrixot helyben a transzlációból Vector3, forgatás Quaternion vagy Vector3 (Euler), és méretezés Vector3 |
to_array() | list[float] | Visszaadja a 16 elemet lapos listaként |
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