scipy.spatial.transform.RigidTransform.

from_matrix#

classmethod RigidTransform.from_matrix(cls, matrix)#

Initialize from a 4x4 transformation matrix.

Parameters:
matrixarray_like, shape (4, 4) or (N, 4, 4)

A single transformation matrix or a stack of transformation matrices.

Returns:
transformRigidTransform instance

Notes

4x4 rigid transformation matrices are of the form:

[R | t] [0 | 1]

where R is a 3x3 rotation matrix and t is a 3x1 translation vector [tx, ty, tz]. As rotation matrices must be proper orthogonal, the rotation component is orthonormalized using singular value decomposition before initialization.

Examples

>>> from scipy.spatial.transform import RigidTransform as Tf
>>> import numpy as np

Creating a transform from a single matrix:

>>> m = np.array([[0, 1, 0, 2],
...               [0, 0, 1, 3],
...               [1, 0, 0, 4],
...               [0, 0, 0, 1]])
>>> tf = Tf.from_matrix(m)
>>> tf.as_matrix()
array([[0., 1., 0., 2.],
       [0., 0., 1., 3.],
       [1., 0., 0., 4.],
       [0., 0., 0., 1.]])
>>> tf.single
True

Creating a transform from a stack of matrices:

>>> m = np.array([np.eye(4), np.eye(4)])
>>> tf = Tf.from_matrix(m)
>>> tf.as_matrix()
array([[[1., 0., 0., 0.],
        [0., 1., 0., 0.],
        [0., 0., 1., 0.],
        [0., 0., 0., 1.]],
       [[1., 0., 0., 0.],
        [0., 1., 0., 0.],
        [0., 0., 1., 0.],
        [0., 0., 0., 1.]]])
>>> tf.single
False
>>> len(tf)
2

Matrices with a rotation component that is not proper orthogonal are orthogonalized using singular value decomposition before initialization:

>>> tf = Tf.from_matrix(np.diag([2, 2, 2, 1]))
>>> tf.as_matrix()
array([[1., 0., 0., 0.],
       [0., 1., 0., 0.],
       [0., 0., 1., 0.],
       [0., 0., 0., 1.]])