decompose_matrix

compas.geometry.decompose_matrix(M)[source]

Calculates the components of rotation, translation, scale, shear, and perspective of a given transformation matrix M. [1]

Parameters:
Mlist[list[float]]

The square matrix of any dimension.

Returns:
scale[float, float, float]

The 3 scale factors in x-, y-, and z-direction.

shear[float, float, float]

The 3 shear factors for x-y, x-z, and y-z axes.

angles[float, float, float]

The rotation specified through the 3 Euler angles about static x, y, z axes.

translation[float, float, float]

The 3 values of translation.

perspective[float, float, float, float]

The 4 perspective entries of the matrix.

Raises:
ValueError

If matrix is singular or degenerative.

See also

compose_matrix

References

[1]

Slabaugh, 1999. Computing Euler angles from a rotation matrix. Available at: http://www.gregslabaugh.net/publications/euler.pdf

Examples

>>> trans1 = [1, 2, 3]
>>> angle1 = [-2.142, 1.141, -0.142]
>>> scale1 = [0.123, 2, 0.5]
>>> T = matrix_from_translation(trans1)
>>> R = matrix_from_euler_angles(angle1)
>>> S = matrix_from_scale_factors(scale1)
>>> M = multiply_matrices(multiply_matrices(T, R), S)
>>> # M = compose_matrix(scale1, None, angle1, trans1, None)
>>> scale2, shear2, angle2, trans2, persp2 = decompose_matrix(M)
>>> allclose(scale1, scale2)
True
>>> allclose(angle1, angle2)
True
>>> allclose(trans1, trans2)
True