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

# as_components

RigidTransform.as_components()

  Return the translation and rotation components of the transform, where the rotation is applied first, followed by the translation.

  4x4 rigid transformation matrices are of the form:

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

  Where `R` is a 3x3 orthonormal rotation matrix and `t = [tx, ty, tz]` is a 3x1 translation vector. This function returns the rotation corresponding to this rotation matrix `r = Rotation.from_matrix(R)` and the translation vector `t`.

  When applying a transform `tf` to a vector `v`, the result is the same as if the rotation and translation components were applied to the vector with the following operation: `tf.apply(v) == translation + rotation.apply(v)`.

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

      The translation of the transform.

    rotation `Rotation` instance

      The rotation of the transform.

  Notes

  Array API Standard Support

  `as_components` 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

  Recover the rotation and translation from a transform:

      >>> t = np.array([2, 3, 4])
      >>> r = R.from_matrix([[0, 0, 1],
      ...                    [1, 0, 0],
      ...                    [0, 1, 0]])
      >>> tf = Tf.from_components(t, r)
      >>> t, r = tf.as_components()
      >>> t
      array([2., 3., 4.])
      >>> r.as_matrix()
      array([[0., 0., 1.],
             [1., 0., 0.],
             [0., 1., 0.]])

  The transform applied to a vector is equivalent to the rotation applied to the vector, followed by the translation:

      >>> t + r.apply([1, 0, 0])
      array([2., 4., 4.])
      >>> tf.apply([1, 0, 0])
      array([2., 4., 4.])