Skip to main content
`Ctrl`+`K`
scipy.spatial.transform.RigidTransform.

# from_matrix

static RigidTransform.from_matrix(matrix)

  Initialize from a 4x4 transformation matrix.

  Parameters:
    matrix array_like, shape (…, 4, 4)

      Transformation matrices. Each matrix[…, :, :] represents a 4x4 transformation matrix.

  Returns:
    transform `RigidTransform` instance

      Object containing the rigid transform represented by the input matrix.

  Notes

  4x4 rigid transformation matrices are of the form:

      [       tx]
      [   R   ty]
      [       tz]
      [ 0 0 0  1]

  where `R` is a 3x3 rotation matrix and `t = [tx, ty, tz]` is a 3x1 translation vector. 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 an N-dimensional array of matrices:

      >>> m = np.tile(np.eye(4), (2, 5, 1, 1))  # Shape (2, 5, 4, 4)
      >>> tf = Tf.from_matrix(m)
      >>> tf.shape
      (2, 5)
      >>> 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.]])