Slerp — SciPy v1.15.1 Manual (original) (raw)

scipy.spatial.transform.

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:

timesarray_like, shape (N,)

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

rotationsRotation instance

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

Notes

Added in version 1.2.0.

References

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

Methods