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

# apply

RigidTransform.apply(self, vector, inverse=False)

  Apply the transform to a vector.

  If the original frame transforms to the final frame by this transform, then its application to a vector can be seen in two ways:

  > - As a projection of vector components expressed in the final frame to the original frame.

  > - As the physical transformation of a vector being glued to the original frame as it transforms. In this case the vector components are expressed in the original frame before and after the transformation.

  In terms of rotation matrices and translation vectors, this application is the same as `self.translation + self.rotation.as_matrix() @ vector`.

  Parameters:
    vector array_like, shape (N, 3) or (3,)

      A single vector or a stack of vectors.

    inverse bool, optional

      If True, the inverse of the transform is applied to the vector.

  Returns:
    transformed_vector numpy.ndarray, shape (N, 3) or (3,)

      The transformed vector(s). Shape depends on the following cases:

      > - If object contains a single transform (as opposed to a stack with a single transform) and a single vector is specified with shape `(3,)`, then transformed_vector has shape `(3,)`.

      > - In all other cases, transformed_vector has shape `(N, 3)`, where `N` is either the number of transforms or vectors.

  Examples

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

  Apply a single transform to a vector. Here the transform is just a translation, so the result is the vector added to the translation vector.

      >>> t = np.array([1, 2, 3])
      >>> tf = Tf.from_translation(t)
      >>> t + np.array([1, 0, 0])
      array([2, 2, 3])
      >>> tf.apply([1, 0, 0])
      array([2., 2., 3.])

  Apply a single transform to a stack of vectors:

      >>> tf.apply([[1, 0, 0], [0, 1, 0]])
      array([[2., 2., 3.],
             [1., 3., 3.]])

  Apply the inverse of a transform to a vector, so the result is the negative of the translation vector added to the vector.

      >>> -t + np.array([1, 0, 0])
      array([0, -2, -3])
      >>> tf.apply([1, 0, 0], inverse=True)
      array([0., -2., -3.])

  For transforms which are not just pure translations, applying it to a vector is the same as applying the rotation component to the vector and then adding the translation component.

      >>> r = R.from_euler('z', 60, degrees=True)
      >>> tf = Tf.from_components(t, r)
      >>> t + r.apply([1, 0, 0])
      array([1.5,       2.8660254, 3.       ])
      >>> tf.apply([1, 0, 0])
      array([1.5,       2.8660254, 3.       ])

  When applying the inverse of a transform, the result is the negative of the translation vector added to the vector, and then rotated by the inverse rotation.

      >>> r.inv().apply(-t + np.array([1, 0, 0]))
      array([-1.73205081, -1.        , -3.        ])
      >>> tf.apply([1, 0, 0], inverse=True)
      array([-1.73205081, -1.        , -3.        ])