Matrix4 — Aspose.3D FOSS for Python API Reference
Overview
Matrix4 is a 4×4 double-precision matrix stored in row-major order with 16 elements (m00–m33). It is used for world/local transform computations, custom projections, and decomposing node transforms into translation, rotation, and scale.
Package: aspose.threed.utilities
from aspose.threed.utilities import Matrix4Constructor
| Signature | Description |
|---|---|
Matrix4() | Identity matrix |
Matrix4(m00, m01, ..., m33) | Explicit 16-element constructor (row-major order) |
Matrix4(values) | Constructs from a list of 16 float values |
Element Properties
Elements are named mRC where R is the row (0–3) and C is the column (0–3). For example, m03 is row 0, column 3 (the X translation when the matrix encodes a transform). All 16 properties (m00 through m33) are readable and writable.
The matrix can also be accessed by flat index: mat[0]–mat[15].
Computed Properties
| Name | Type | Description |
|---|---|---|
determinant | float | Scalar determinant of the matrix |
Static Factory Methods
| Method | Return Type | Description |
|---|---|---|
Matrix4.get_identity() | Matrix4 | Returns an identity matrix |
Matrix4.translate(tx, ty, tz) | Matrix4 | Translation matrix; also accepts a Vector3 or a single scalar for uniform translation |
Matrix4.scale(sx, sy, sz) | Matrix4 | Scale matrix; also accepts a Vector3 or a single scalar for uniform scale |
Matrix4.rotate(angle, axis) | Matrix4 | Rotation matrix from angle (radians) and Vector3 axis; also accepts a Quaternion as the sole argument |
Matrix4.rotate_from_euler(rx, ry, rz) | Matrix4 | Rotation matrix from Euler angles (radians); also accepts a Vector3 |
Instance Methods
| Method | Return Type | Description |
|---|---|---|
concatenate(m2) | Matrix4 | Returns the matrix product self × m2 |
normalize() | Matrix4 | Returns a copy with the rotation axes re-orthonormalized (scale removed from rotation columns) |
transpose() | Matrix4 | Returns the transposed matrix |
inverse() | Matrix4 | Returns the inverse; raises ValueError if the matrix is singular |
decompose(translation, scaling, rotation) | None | Decomposes into TRS components. Results are written into single-element lists: translation[0] → Vector3, scaling[0] → Vector3, rotation[0] → Quaternion |
set_trs(translation, rotation, scale) | None | Sets matrix in-place from translation Vector3, rotation Quaternion or Vector3 (Euler), and scale Vector3 |
to_array() | list[float] | Returns the 16 elements as a flat list |
Example
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