Uranium
Application Framework
UM.Math.Matrix.Matrix Class Reference

This class is a 4x4 homogeneous matrix wrapper around numpy. More...

Public Member Functions

None __init__ (self, Optional[Union[List[List[float]], numpy.array]] data=None)
 
def __deepcopy__ (self, memo)
 
"Matrix" copy (self)
 
bool __eq__ (self, object other)
 
float at (self, int x, int y)
 
None setRow (self, int index, List[float] value)
 
None setColumn (self, int index, List[float] value)
 
"Matrix" multiply (self, Union[Vector, "Matrix"] other, bool copy=False)
 
"Matrix" preMultiply (self, Union[Vector, "Matrix"] other, bool copy=False)
 
numpy.ndarray getData (self)
 Get raw data. More...
 
None setToIdentity (self)
 Create a 4x4 identity matrix. More...
 
None invert (self)
 Invert the matrix.
 
"Matrix" getInverse (self)
 Return a inverted copy of the matrix. More...
 
"Matrix" getTransposed (self)
 Return the transpose of the matrix. More...
 
None transpose (self)
 
None translate (self, Vector direction)
 Translate the matrix based on Vector. More...
 
None setByTranslation (self, Vector direction)
 Set the matrix by translation vector. More...
 
None setTranslation (self, Union[Vector, "Matrix"] translation)
 
Vector getTranslation (self)
 
None rotateByAxis (self, float angle, Vector direction, Optional[List[float]] point=None)
 Rotate the matrix based on rotation axis. More...
 
None setByRotationAxis (self, float angle, Vector direction, Optional[List[float]] point=None)
 Set the matrix based on rotation axis. More...
 
None compose (self, Vector scale=None, Vector shear=None, Vector angles=None, Vector translate=None, Vector perspective=None, Vector mirror=None)
 Return transformation matrix from sequence of transformations. More...
 
Vector getEuler (self, str axes="sxyz")
 Return Euler angles from rotation matrix for specified axis sequence. More...
 
None setByEuler (self, float ai, float aj, float ak, str axes="sxyz")
 Return homogeneous rotation matrix from Euler angles and axis sequence. More...
 
None scaleByFactor (self, float factor, Optional[List[float]] origin=None, Optional[Vector] direction=None)
 Scale the matrix by factor wrt origin & direction. More...
 
None setByScaleFactor (self, float factor, Optional[List[float]] origin=None, Optional[Vector] direction=None)
 Set the matrix by scale by factor wrt origin & direction. More...
 
None setByScaleVector (self, Vector scale)
 
Vector getScale (self)
 
None setOrtho (self, float left, float right, float bottom, float top, float near, float far)
 Set the matrix to an orthographic projection. More...
 
None setPerspective (self, float fovy, float aspect, float near, float far)
 Set the matrix to a perspective projection. More...
 
def decompose (self)
 
str __repr__ (self)
 

Static Public Member Functions

"Matrix" fromPositionOrientationScale (Vector position, "Quaternion" orientation, Vector scale)
 

Detailed Description

This class is a 4x4 homogeneous matrix wrapper around numpy.

Heavily based (in most cases a straight copy with some refactoring) on the excellent 'library' Transformations.py created by Christoph Gohlke.

Member Function Documentation

◆ compose()

None UM.Math.Matrix.Matrix.compose (   self,
Vector   scale = None,
Vector   shear = None,
Vector   angles = None,
Vector   translate = None,
Vector   perspective = None,
Vector   mirror = None 
)

Return transformation matrix from sequence of transformations.

This is the inverse of the decompose_matrix function.

Parameters
scale: vector of 3 scaling factors
shear: list of shear factors for x-y, x-z, y-z axes
angles: list of Euler angles about static x, y, z axes
translate: translation vector along x, y, z axes
perspective: perspective partition of matrix
mirrorvector with mirror factors (1 if that axis is not mirrored, -1 if it is)

◆ decompose()

def UM.Math.Matrix.Matrix.decompose (   self)
SOURCE: https://github.com/matthew-brett/transforms3d/blob/e402e56686648d9a88aa048068333b41daa69d1a/transforms3d/affines.py
Decompose 4x4 homogenous affine matrix into parts.
The parts are translations, rotations, zooms, shears.
This is the same as :func:`decompose` but specialized for 4x4 affines.
Decomposes `A44` into ``T, R, Z, S``, such that::
   Smat = np.array([[1, S[0], S[1]],
            [0,    1, S[2]],
            [0,    0,    1]])
   RZS = np.dot(R, np.dot(np.diag(Z), Smat))
   A44 = np.eye(4)
   A44[:3,:3] = RZS
   A44[:-1,-1] = T
The order of transformations is therefore shears, followed by
zooms, followed by rotations, followed by translations.
This routine only works for shape (4,4) matrices
Parameters
----------
A44 : array shape (4,4)
Returns
-------
T : array, shape (3,)
   Translation vector
R : array shape (3,3)
    rotation matrix
Z : array, shape (3,)
   Zoom vector.  May have one negative zoom to prevent need for negative
   determinant R matrix above
S : array, shape (3,)
   Shear vector, such that shears fill upper triangle above
   diagonal to form shear matrix (type ``striu``).

◆ getData()

numpy.ndarray UM.Math.Matrix.Matrix.getData (   self)

Get raw data.

Returns
4x4 numpy array

◆ getEuler()

Vector UM.Math.Matrix.Matrix.getEuler (   self,
str   axes = "sxyz" 
)

Return Euler angles from rotation matrix for specified axis sequence.

axes : One of 24 axis sequences as string or encoded tuple Note that many Euler angle triplets can describe one matrix.

◆ getInverse()

"Matrix" UM.Math.Matrix.Matrix.getInverse (   self)

Return a inverted copy of the matrix.

Returns
The invertex matrix.

◆ getTransposed()

"Matrix" UM.Math.Matrix.Matrix.getTransposed (   self)

Return the transpose of the matrix.

◆ rotateByAxis()

None UM.Math.Matrix.Matrix.rotateByAxis (   self,
float  angle,
Vector  direction,
Optional[List[float]]   point = None 
)

Rotate the matrix based on rotation axis.

Parameters
angleThe angle by which matrix needs to be rotated.
directionAxis by which the matrix needs to be rotated about.
pointPoint where from where the rotation happens. If None, origin is used.

◆ scaleByFactor()

None UM.Math.Matrix.Matrix.scaleByFactor (   self,
float  factor,
Optional[List[float]]   origin = None,
Optional[Vector]   direction = None 
)

Scale the matrix by factor wrt origin & direction.

Parameters
factorThe factor by which to scale
originFrom where does the scaling need to be done
directionIn what direction is the scaling (if None, it's uniform)

◆ setByEuler()

None UM.Math.Matrix.Matrix.setByEuler (   self,
float  ai,
float  aj,
float  ak,
str   axes = "sxyz" 
)

Return homogeneous rotation matrix from Euler angles and axis sequence.

Parameters
aiEulers roll
ajEulers pitch
akEulers yaw
axesOne of 24 axis sequences as string or encoded tuple

◆ setByRotationAxis()

None UM.Math.Matrix.Matrix.setByRotationAxis (   self,
float  angle,
Vector  direction,
Optional[List[float]]   point = None 
)

Set the matrix based on rotation axis.

This overwrites any existing data.

Parameters
angleThe angle by which matrix needs to be rotated in radians.
directionAxis by which the matrix needs to be rotated about.
pointPoint where from where the rotation happens. If None, origin is used.

◆ setByScaleFactor()

None UM.Math.Matrix.Matrix.setByScaleFactor (   self,
float  factor,
Optional[List[float]]   origin = None,
Optional[Vector]   direction = None 
)

Set the matrix by scale by factor wrt origin & direction.

This overwrites any existing data

Parameters
factorThe factor by which to scale
originFrom where does the scaling need to be done
directionIn what direction is the scaling (if None, it's uniform)

◆ setByTranslation()

None UM.Math.Matrix.Matrix.setByTranslation (   self,
Vector  direction 
)

Set the matrix by translation vector.

This overwrites any existing data.

Parameters
directionThe vector by which the (unit) matrix needs to be translated.

◆ setOrtho()

None UM.Math.Matrix.Matrix.setOrtho (   self,
float  left,
float  right,
float  bottom,
float  top,
float  near,
float  far 
)

Set the matrix to an orthographic projection.

This overwrites any existing data.

Parameters
leftThe left edge of the projection
rightThe right edge of the projection
topThe top edge of the projection
bottomThe bottom edge of the projection
nearThe near plane of the projection
farThe far plane of the projection

◆ setPerspective()

None UM.Math.Matrix.Matrix.setPerspective (   self,
float  fovy,
float  aspect,
float  near,
float  far 
)

Set the matrix to a perspective projection.

This overwrites any existing data.

Parameters
fovyField of view in the Y direction
aspectThe aspect ratio
nearDistance to the near plane
farDistance to the far plane

◆ setToIdentity()

None UM.Math.Matrix.Matrix.setToIdentity (   self)

Create a 4x4 identity matrix.

This overwrites any existing data.

◆ translate()

None UM.Math.Matrix.Matrix.translate (   self,
Vector  direction 
)

Translate the matrix based on Vector.

Parameters
directionThe vector by which the matrix needs to be translated.

The documentation for this class was generated from the following file: