slerp
Performs Spherical Linear Interpolation (Slerp) between two quaternions, start and endInput, by an interpolant tOriginal. Slerp provides smooth interpolation of rotations with constant angular velocity along the shortest path on the 4D unit sphere.
The process involves:
Clamping the interpolant
tOriginalto the range[0.0, 1.0]. Exactt=0.0ort=1.0returns the normalized start or end quaternion respectively.Ensuring the interpolation takes the shortest path on the 4D sphere by negating
endInputif its dot product withstartis negative.If the two quaternions (after shortest path adjustment) are nearly collinear (i.e., the angle between them is very small,
cos(theta)is close to 1, checked using1e-6f), this function falls back to Normalized Linear Interpolation (Nlerp) for numerical stability and efficiency.Otherwise, the standard Slerp formula is used.
The final result is normalized to ensure it remains a unit quaternion, robust against potential floating-point inaccuracies.
Both input quaternions start and endInput should ideally be unit quaternions representing rotations for Slerp to be geometrically meaningful. The function attempts to return a normalized quaternion regardless by normalizing at endpoints and for the final result.
Return
A new unit Quat representing the spherically interpolated rotation.