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

# apply

RigidTransform.apply(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 (…, 3)

      Vector(s) to be transformed. Each vector[…, :] represents a 3D vector.

    inverse bool, optional

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

  Returns:
    transformed_vector numpy.ndarray, shape (…, 3)

      The transformed vector(s) with shape determined by broadcasting the transform and vector shapes together.

  Notes

  Array API Standard Support

  `apply` has experimental support for Python Array API Standard compatible backends in addition to NumPy. Please consider testing these features by setting an environment variable `SCIPY_ARRAY_API=1` and providing CuPy, PyTorch, JAX, or Dask arrays as array arguments. The following combinations of backend and device (or other capability) are supported.

  Library | CPU | GPU
  --- | --- | ---
  NumPy | ✅ | n/a
  CuPy | n/a | ⛔
  PyTorch | ✅ | ✅
  JAX | ✅ | ✅
  Dask | ⛔ | n/a

  > See Support for the array API standard for more information.

  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.])

  Broadcasting is supported when applying multiple transforms to an N-dimensional array of vectors.

      >>> tf = Tf.from_translation(np.ones((4, 5, 1, 3)))
      >>> vectors = np.zeros((2, 3))
      >>> tf.apply(vectors).shape
      (4, 5, 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.        ])