Uranium
Application Framework
Loading...
Searching...
No Matches
UM.Math.Matrix.Matrix Class Reference

Public Member Functions

None __init__ (self, Optional[Union[List[List[float]], numpy.ndarray]] data=None)
 
 __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)
 
 getFlatData (self)
 
None setToIdentity (self)
 
None invert (self)
 
None pseudoinvert (self)
 
"Matrix" getInverse (self)
 
"Matrix" getTransposed (self)
 
None transpose (self)
 
None translate (self, Vector direction)
 
None setByTranslation (self, Vector direction)
 
None setTranslation (self, Union[Vector, "Matrix"] translation)
 
Vector getTranslation (self)
 
None rotateByAxis (self, float angle, Vector direction, Optional[List[float]] point=None)
 
None setByRotationAxis (self, float angle, Vector direction, Optional[List[float]] point=None)
 
None compose (self, Vector scale=None, Vector shear=None, Vector angles=None, Vector translate=None, Vector perspective=None, Vector mirror=None)
 
Vector getEuler (self, str axes="sxyz")
 
None setByEuler (self, float ai, float aj, float ak, str axes="sxyz")
 
None scaleByFactor (self, float factor, Optional[List[float]] origin=None, Optional[Vector] direction=None)
 
None setByScaleFactor (self, float factor, Optional[List[float]] origin=None, Optional[Vector] direction=None)
 
None setByScaleVector (self, Vector scale)
 
Vector getScale (self)
 
None setOrtho (self, float left, float right, float bottom, float top, float near, float far)
 
None setPerspective (self, float fovy, float aspect, float near, float far)
 
Tuple[Vector, "Matrix", Vector, Vectordecompose (self)
 
str __repr__ (self)
 

Static Public Member Functions

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

Protected Member Functions

Optional[numpy.ndarray] _unitVector (self, numpy.ndarray data, Optional[int] axis=None, Optional[numpy.ndarray] out=None)
 

Protected Attributes

None _data = numpy.identity(4, dtype = numpy.float64)
 

Static Protected Attributes

float _EPS = numpy.finfo(float).eps * 4.0
 
dict _AXES2TUPLE
 
list _NEXT_AXIS = [1, 2, 0, 1]
 

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

◆ _unitVector()

Optional[numpy.ndarray] UM.Math.Matrix.Matrix._unitVector ( self,
numpy.ndarray data,
Optional[int] axis = None,
Optional[numpy.ndarray] out = None )
protected
Return ndarray normalized by length, i.e. Euclidean norm, along axis.
>>> matrix = Matrix()
>>> v0 = numpy.random.random(3)
>>> v1 = matrix._unitVector(v0)
>>> numpy.allclose(v1, v0 / numpy.linalg.norm(v0))
True
>>> v0 = numpy.random.rand(5, 4, 3)
>>> v1 = matrix._unitVector(v0, axis=-1)
>>> v2 = v0 / numpy.expand_dims(numpy.sqrt(numpy.sum(v0 * v0, axis=2)), 2)
>>> numpy.allclose(v1, v2)
True
>>> v1 = matrix._unitVector(v0, axis=1)
>>> v2 = v0 / numpy.expand_dims(numpy.sqrt(numpy.sum(v0 * v0, axis=1)), 1)
>>> numpy.allclose(v1, v2)
True
>>> v1 = numpy.empty((5, 4, 3))
>>> matrix._unitVector(v0, axis=1, out=v1)
>>> numpy.allclose(v1, v2)
True
>>> list(matrix._unitVector([]))
[]
>>> list(matrix._unitVector([1]))
[1.0]

◆ 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.
:param scale : vector of 3 scaling factors
:param shear : list of shear factors for x-y, x-z, y-z axes
:param angles : list of Euler angles about static x, y, z axes
:param translate : translation vector along x, y, z axes
:param perspective : perspective partition of matrix
:param mirror: vector with mirror factors (1 if that axis is not mirrored, -1 if it is)

◆ decompose()

Tuple[Vector, "Matrix", Vector, Vector] 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.

:param 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.

◆ invert()

None UM.Math.Matrix.Matrix.invert ( self)
Invert the matrix

◆ pseudoinvert()

None UM.Math.Matrix.Matrix.pseudoinvert ( self)
Invert the matrix in-place with a pseudoinverse.

The pseudoinverse is guaranteed to succeed, but if the matrix was singular is not a true inverse. Just something
that approaches the inverse.

◆ rotateByAxis()

None UM.Math.Matrix.Matrix.rotateByAxis ( self,
float angle,
Vector direction,
Optional[List[float]] point = None )
Rotate the matrix based on rotation axis
:param angle: The angle by which matrix needs to be rotated.
:param direction: Axis by which the matrix needs to be rotated about.
:param point: Point 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.

:param factor: The factor by which to scale
:param origin: From where does the scaling need to be done
:param direction: In 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.
:param ai: Eulers roll
:param aj: Eulers pitch
:param ak: Eulers yaw
:param axes: One 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.
:param angle: The angle by which matrix needs to be rotated in radians.
:param direction: Axis by which the matrix needs to be rotated about.
:param point: Point 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

:param factor: The factor by which to scale
:param origin: From where does the scaling need to be done
:param direction: In 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.
:param direction: The 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.

:param left: The left edge of the projection
:param right: The right edge of the projection
:param top: The top edge of the projection
:param bottom: The bottom edge of the projection
:param near: The near plane of the projection
:param far: The 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.

:param fovy: Field of view in the Y direction
:param aspect: The aspect ratio
:param near: Distance to the near plane
:param far: Distance 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.
:param direction: The vector by which the matrix needs to be translated.

Member Data Documentation

◆ _AXES2TUPLE

dict UM.Math.Matrix.Matrix._AXES2TUPLE
staticprotected
Initial value:
= {
"sxyz": (0, 0, 0, 0), "sxyx": (0, 0, 1, 0), "sxzy": (0, 1, 0, 0),
"sxzx": (0, 1, 1, 0), "syzx": (1, 0, 0, 0), "syzy": (1, 0, 1, 0),
"syxz": (1, 1, 0, 0), "syxy": (1, 1, 1, 0), "szxy": (2, 0, 0, 0),
"szxz": (2, 0, 1, 0), "szyx": (2, 1, 0, 0), "szyz": (2, 1, 1, 0),
"rzyx": (0, 0, 0, 1), "rxyx": (0, 0, 1, 1), "ryzx": (0, 1, 0, 1),
"rxzx": (0, 1, 1, 1), "rxzy": (1, 0, 0, 1), "ryzy": (1, 0, 1, 1),
"rzxy": (1, 1, 0, 1), "ryxy": (1, 1, 1, 1), "ryxz": (2, 0, 0, 1),
"rzxz": (2, 0, 1, 1), "rxyz": (2, 1, 0, 1), "rzyz": (2, 1, 1, 1)
}

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