matrix.Matrix4x4
- class matrix.Matrix4x4(x00=0.0, x01=0.0, x02=0.0, x03=0.0, x10=0.0, x11=0.0, x12=0.0, x13=0.0, x20=0.0, x21=0.0, x22=0.0, x23=0.0, x30=0.0, x31=0.0, x32=0.0, x33=0.0)
Class for representing 3D transformations with homogenous coordinates.
Each
Matrix4x4
is immutable and it’s methods return new copies of matrices instead of modifying the original.This class is just a wrapper around the Unity matrix class which you can find here.
In addition to the methods listed here,
Matrix4x4
supports the infix operator*
between matrices as matrix multiplication (composition) and also between a matrix on the left and aVector3
on the right as multiplication with the vector in column form.Matrix4x4
also implements__getitem__
with tuples ofint
s corresponding to the row and column indices respectively each from0
to3
inclusive. Negative values and slices work in the usual way for python iterables.Generally, methods that take in a matrix also accept 16-tuples or lists of length 16 or 4 by 4 square tuples or lists in row major form.
- static from_rotation(axis: vector.Vector3, radians: Optional[float] = None) matrix.Matrix4x4
Returns a rotation matrix corresponding to the a rotation around
axis
byradians
radians. If radians is not supplied orNone
, then the magnitude ofaxis
is used. Ifradians
is supplied, the magnitude ofaxis
is ignored.See https://docs.unity3d.com/ScriptReference/Matrix4x4.Rotate.html.
- static from_scale(scale: vector.Vector3) matrix.Matrix4x4
Creates a scaling matrix with
scale
‘s values on the diagonal.See https://docs.unity3d.com/ScriptReference/Matrix4x4.Scale.html.
- static from_translation(translation: vector.Vector3)
Creates a translation matrix with
translation
laid out in the fourth column.See https://docs.unity3d.com/ScriptReference/Matrix4x4.Translate.html.
- rotation_axis() Optional[vector.Vector3]
Returns the rotation component of the matrix as a rotation axis with magnitude in radians. Returns
None
if the matrix is not a valid affine transformation.See https://docs.unity3d.com/ScriptReference/Matrix4x4-rotation.html.
- static identity() matrix.Matrix4x4
Returns the identity matrix with
1
’s along the diagonal.See https://docs.unity3d.com/ScriptReference/Matrix4x4-identity.html.
- static zero() matrix.Matrix4x4
Returns the zero matrix of all zeros. This isn’t a valid affine transformation because the final
1
is missing.See https://docs.unity3d.com/ScriptReference/Matrix4x4-zero.html.
- determinant() float
Returns the determinant of the matrix.
See https://docs.unity3d.com/ScriptReference/Matrix4x4-determinant.html.
- inverse() Optional[matrix.Matrix4x4]
Returns the inverse of the matrix if its determinant is non-zero. Returns
None
otherwise.See https://docs.unity3d.com/ScriptReference/Matrix4x4-inverse.html.
- is_identity() bool
Returns
True
if the matrix is an identity transformation. ReturnsFalse
otherwise.See https://docs.unity3d.com/ScriptReference/Matrix4x4-isIdentity.html.
- lossy_scale() vector.Vector3
Returns the scale of the matrix in vector form. Assumes that the matrix orthogonal.
See https://docs.unity3d.com/ScriptReference/Matrix4x4-lossyScale.html.
- column(j: int) Tuple[float, float, float, float]
Returns
j
th column of the matrix as a 4-tuple. As an alternative, slicing may be used to get an iterable that visits each value in a column like so:m[i::4]
.See https://docs.unity3d.com/ScriptReference/Matrix4x4.GetColumn.html.
- row(i: int) Tuple[float, float, float, float]
Returns the
i
th row in the matrix as a 4-tuple. As an alternative, slicing may be used to get an iterable that visits each value in a row like so:m[i:i+4]
.See https://docs.unity3d.com/ScriptReference/Matrix4x4.GetRow.html.
- position() vector.Vector3
Returns the translation component of the matrix.
m.position()
is equivalent tom * (0,0,0)
See https://docs.unity3d.com/ScriptReference/Matrix4x4.GetPosition.html.
- transform_direction(v: vector.Vector3) vector.Vector3
Returns
v
transformed by the 3x3 part of the matrix, leaving out the translational part. This is useful ifv
represents a positionless vector (i.e. a direction).See https://docs.unity3d.com/ScriptReference/Matrix4x4.MultiplyVector.html.
- but_with(row: int, col: int, value: float) matrix.Matrix4x4
Returns a new matrix that is the same as the calling matrix, except the value at row
row
and columncol
is replaced withvalue
.
- but_with_row(index: int, values: Tuple[float, float, float, float]) matrix.Matrix4x4
Returns a new matrix that is the same as the calling matrix, except row
index
is replaced the values invalues
.values
can be anything with length 4.
- but_with_col(index: int, values: Tuple[float, float, float, float]) matrix.Matrix4x4
Returns a new matrix that is the same as the calling matrix, except column
index
is replaced the values invalues
.values
can be anything with length 4.
- static from_components(position: vector.Vector3, rotation_axis: vector.Vector3, scale: vector.Vector3) matrix.Matrix4x4
Returns a matrix made out of a position/translation, rotation, and scale components.
rotation_axis
is a rotation axis with magnitude in radians.See https://docs.unity3d.com/ScriptReference/Matrix4x4.TRS.html:
- decomposable() bool
Returns
True
iff the matrix a valid transformation that can decomposed into a translation, rotation, and scale components.See https://docs.unity3d.com/ScriptReference/Matrix4x4.ValidTRS.html.
- look_at(target: vector.Vector3, up: vector.Vector3) matrix.Matrix4x4
Returns a matrix representing a left-handed coordinate system with origin
origin
, the z vector pointing towardstarget
fromorigin
and the y vector lying on the plane defined byup
and the new z vector.See https://docs.unity3d.com/ScriptReference/Matrix4x4.LookAt.html