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

# inv

RigidTransform.inv()

  Invert this transform.

  Composition of a transform with its inverse results in an identity transform.

  A rigid transform is a composition of a rotation and a translation, where the rotation is applied first, followed by the translation. So the inverse transform is equivalent to the inverse translation followed by the inverse rotation.

  Returns:
    `RigidTransform` instance

      The inverse of this transform.

  Notes

  Array API Standard Support

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

  A transform composed with its inverse results in an identity transform:

      >>> rng = np.random.default_rng(seed=123)
      >>> t = rng.random(3)
      >>> r = R.random(rng=rng)
      >>> tf = Tf.from_components(t, r)
      >>> tf.as_matrix()
      array([[-0.45431291,  0.67276178, -0.58394466,  0.68235186],
             [-0.23272031,  0.54310598,  0.80676958,  0.05382102],
             [ 0.85990758,  0.50242162, -0.09017473,  0.22035987],
             [ 0.        ,  0.        ,  0.        ,  1.        ]])

      >>> (tf.inv() * tf).as_matrix()
      array([[[1., 0., 0., 0.],
              [0., 1., 0., 0.],
              [0., 0., 1., 0.],
              [0., 0., 0., 1.]]])

  The inverse rigid transform is the same as the inverse translation followed by the inverse rotation:

      >>> t, r = tf.as_components()
      >>> r_inv = r.inv()  # inverse rotation
      >>> t_inv = -t  # inverse translation
      >>> tf_r_inv = Tf.from_rotation(r_inv)
      >>> tf_t_inv = Tf.from_translation(t_inv)
      >>> np.allclose((tf_r_inv * tf_t_inv).as_matrix(),
      ...             tf.inv().as_matrix(),
      ...             atol=1e-12)
      True
      >>> (tf_r_inv * tf_t_inv * tf).as_matrix()
      array([[[1., 0., 0., 0.],
              [0., 1., 0., 0.],
              [0., 0., 1., 0.],
              [0., 0., 0., 1.]]])