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

# Slerp

class scipy.spatial.transform.Slerp(times, rotations)

  Spherical Linear Interpolation of Rotations.

  The interpolation between consecutive rotations is performed as a rotation around a fixed axis with a constant angular velocity [1]. This ensures that the interpolated rotations follow the shortest path between initial and final orientations.

  Parameters:
    times array_like, shape (N,)

      Times of the known rotations. At least 2 times must be specified.

    rotations `Rotation` instance

      Rotations to perform the interpolation between. Must contain N rotations.

  Methods

  `__call__`(times) | Interpolate rotations.

  See also

  `Rotation`

  Notes

  This class only supports interpolation of rotations with a single leading dimension.

  Added in version 1.2.0.

  Array API Standard Support

  `Slerp` 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.

  References

  [1]

  https://en.wikipedia.org/wiki/Slerp#Quaternion_Slerp

  Examples

      >>> from scipy.spatial.transform import Rotation as R
      >>> from scipy.spatial.transform import Slerp

  Setup the fixed keyframe rotations and times:

      >>> key_rots = R.random(5, random_state=2342345)
      >>> key_times = [0, 1, 2, 3, 4]

  Create the interpolator object:

      >>> slerp = Slerp(key_times, key_rots)

  Interpolate the rotations at the given times:

      >>> times = [0, 0.5, 0.25, 1, 1.5, 2, 2.75, 3, 3.25, 3.60, 4]
      >>> interp_rots = slerp(times)

  The keyframe rotations expressed as Euler angles:

      >>> key_rots.as_euler('xyz', degrees=True)
      array([[ 14.31443779, -27.50095894,  -3.7275787 ],
             [ -1.79924227, -24.69421529, 164.57701743],
             [146.15020772,  43.22849451, -31.34891088],
             [ 46.39959442,  11.62126073, -45.99719267],
             [-88.94647804, -49.64400082, -65.80546984]])

  The interpolated rotations expressed as Euler angles. These agree with the keyframe rotations at both endpoints of the range of keyframe times.

      >>> interp_rots.as_euler('xyz', degrees=True)
      array([[  14.31443779,  -27.50095894,   -3.7275787 ],
             [   4.74588574,  -32.44683966,   81.25139984],
             [  10.71094749,  -31.56690154,   38.06896408],
             [  -1.79924227,  -24.69421529,  164.57701743],
             [  11.72796022,   51.64207311, -171.7374683 ],
             [ 146.15020772,   43.22849451,  -31.34891088],
             [  68.10921869,   20.67625074,  -48.74886034],
             [  46.39959442,   11.62126073,  -45.99719267],
             [  12.35552615,    4.21525086,  -64.89288124],
             [ -30.08117143,  -19.90769513,  -78.98121326],
             [ -88.94647804,  -49.64400082,  -65.80546984]])