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

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

Public Member Functions

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

Static Public Member Functions

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

Protected Member Functions

 _unitVector (self, data, axis=None, out=None)
 

Protected Attributes

 _data
 

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()

UM.Math.Matrix.Matrix._unitVector (   self,
  data,
  axis = None,
  out = None 
)
protected
Return ndarray normalized by length, i.e. Euclidean norm, along axis.

>>> v0 = numpy.random.random(3)
>>> v1 = unit_vector(v0)
>>> numpy.allclose(v1, v0 / numpy.linalg.norm(v0))
True
>>> v0 = numpy.random.rand(5, 4, 3)
>>> v1 = unit_vector(v0, axis=-1)
>>> v2 = v0 / numpy.expand_dims(numpy.sqrt(numpy.sum(v0*v0, axis=2)), 2)
>>> numpy.allclose(v1, v2)
True
>>> v1 = unit_vector(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))
>>> unit_vector(v0, axis=1, out=v1)
>>> numpy.allclose(v1, v2)
True
>>> list(unit_vector([]))
[]
>>> list(unit_vector([1]))
[1.0]

◆ compose()

UM.Math.Matrix.Matrix.compose (   self,
Vector   scale = None,
Vector   shear = None,
Vector   angles = None,
Vector   translate = None,
  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()

UM.Math.Matrix.Matrix.decompose (   self)

Return sequence of transformations from transformation matrix.

Returns
Tuple containing scale (vector), shear (vector), angles (vector) and translation (vector) It will raise a ValueError if matrix is of wrong type or degenerative.

◆ getData()

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

Get raw data.

Returns
4x4 numpy array

◆ getEuler()

UM.Math.Matrix.Matrix.getEuler (   self,
  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.

◆ rotateByAxis()

UM.Math.Matrix.Matrix.rotateByAxis (   self,
  angle,
Vector  direction,
Optional[Vector]   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()

UM.Math.Matrix.Matrix.scaleByFactor (   self,
  factor,
Optional[Vector]   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()

UM.Math.Matrix.Matrix.setByEuler (   self,
  ai,
  aj,
  ak,
  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()

UM.Math.Matrix.Matrix.setByRotationAxis (   self,
  angle,
Vector  direction,
Optional[Vector]   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()

UM.Math.Matrix.Matrix.setByScaleFactor (   self,
  factor,
Optional[Vector]   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()

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()

UM.Math.Matrix.Matrix.setOrtho (   self,
  left,
  right,
  bottom,
  top,
  near,
  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()

UM.Math.Matrix.Matrix.setPerspective (   self,
  fovy,
  aspect,
  near,
  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()

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

Create a 4x4 identity matrix.

This overwrites any existing data.

◆ translate()

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.

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: