Spherical interpolation between two unit quaternions: constant angular speed from start at t = 0 to end at t = 1. If the two are on opposite sides (negative dot product) it interpolates towards the negated end, so it takes the shorter rotation. Very close quaternions use nlerp to avoid dividing by a near-zero sine. The inputs must be unit length; t outside [0, 1] extrapolates.
a := Quaternion.{};
b: Quaternion;
set_from_axis_and_angle(*b, xyz(0, 0, 1), PI / 2);
half := slerp(a, b, 0.5);
_, _, _, angle := get_axis_and_angle(half);
assert(abs(angle - PI64 / 4) < 0.0001);slerp :: (start: Quaternion, end: Quaternion, t: float) -> Quaternion
Interpolates along the shorter arc at constant angular speed. Falls back to nlerp when the two
are nearly parallel.
Parameters
- start: Quaternion
- the quaternion at
t0. - end: Quaternion
- the quaternion at
t1. - t: float
- how far from
starttoend, from 0 to 1.