When interpolating between two unit quaternions, how do slerp and nlerp differ in cost and angular speed, and when is nlerp good enough?
answer
- same arc, different schedule
- acos and sines versus one normalise
- speed bulge in the middle
- error grows with the angle
basics
~20 sSlerp moves along the arc between two unit quaternions at constant angular speed but needs an inverse cosine and sines; nlerp normalises a plain lerp, follows the same arc far more cheaply, and runs faster mid-way, an error negligible for small angles.
solid answer
~50 sSlerp computes `slerp(q0, q1, t) = (sin((1-t)*W)*q0 + sin(t*W)*q1) / sin(W)` with `cos(W) = dot(q0, q1)`, so the rotation advances at a constant angular speed and stays unit length; it costs an inverse cosine, sines and a division, and needs a fallback when `sin(W)` nears zero. Nlerp is `normalise((1-t)*q0 + t*q1)`: a lerp and one inverse square root. It traces exactly the same arc, but the point moves faster in the middle than at the ends. For a 90-degree turn it is under a degree off slerp at worst; for a 180-degree turn the middle runs about 27% faster than average. So nlerp is fine for per-frame smoothing and nearby samples, and is order-independent when blending several weighted rotations; slerp matters for large single-step turns that must look even. Both need the dot-product sign check first.
go deeper
Recall that slerp keeps a constant angular speed and that nlerp is a lerp followed by normalising the result.
Explain that both follow the same arc, why nlerp speeds up mid-way, and why slerp needs a fallback when the inputs nearly coincide.
Choose per case: nlerp for per-frame smoothing and close samples, slerp for large single-step turns, and check both against the sign of the dot product.
Set the default for the codebase, typically nlerp with a slerp option, and measure the angular error at the largest angles real content produces before mandating either.
## The problem both solve Given two orientations as unit quaternions `q0` and `q1`, an interpolation produces in-between orientations for `t` from 0 to 1, for a flight camera blending from a cockpit view to a chase view or a turret easing toward its aim. Unit quaternions lie on a four-dimensional unit sphere, and the natural path is the **great-circle arc** between the two points. The two common methods follow that arc and differ in **when** each point is reached. Both assume `dot(q0, q1) >= 0`. Because `q` and `-q` are one rotation, a negative dot product means the arc goes the long way; negating one input first is mandatory for either method. ## Slerp: constant angular speed Spherical linear interpolation weights the endpoints with sines of the arc angle `W`, where `cos(W) = dot(q0, q1)`: `slerp(q0, q1, t) = (sin((1-t)*W) * q0 + sin(t*W) * q1) / sin(W)` Properties: - **constant angular speed**: equal steps in `t` give equal angles of rotation; - **unit length** by construction, so no normalising is needed; - **cost**: an inverse cosine, sine evaluations and a division per call; - **degenerate case**: when the inputs nearly coincide, `sin(W)` approaches zero and the weights divide by almost nothing, so robust code switches to nlerp when the dot product is close to 1. The rotation angle between the orientations is `2*W`, twice the arc angle on the quaternion sphere. ## Nlerp: the same arc, uneven schedule Normalised lerp blends linearly and projects back onto the sphere: `nlerp(q0, q1, t) = normalise((1-t)*q0 + t*q1)` The straight chord between `q0` and `q1` lies in the plane through both and the origin, so normalising each chord point lands on the **same great-circle arc** slerp uses. What changes is the timing: points near the middle of the chord are projected through a wider angle than points near the ends. | Turn between orientations | Worst-case angle error vs slerp | Speed at the middle vs average | Speed at the ends vs average | |---|---|---|---| | 30 degrees | about 0.03 degrees | under 1% faster | about 1% slower | | 90 degrees | about 0.9 degrees | about 6% faster | about 10% slower | | 180 degrees | about 8 degrees | about 27% faster | about 36% slower | The error is zero at `t = 0`, `0.5` and `1`, by symmetry, and largest roughly a quarter of the way from either end. ## Choosing between them 1. **Per-frame smoothing toward a moving target**: each frame covers a small angle, so nlerp's error is invisible and its cost is a fraction of slerp's. 2. **Densely sampled orientation data**: neighbouring samples are close, so nlerp is the usual choice. 3. **One large turn that must look even**, such as a scripted camera swinging 150 degrees over two seconds: slerp, or the speed bulge shows. 4. **Blending more than two orientations with weights**: nlerp extends naturally as `normalise(sum of w_i*q_i)` after aligning every sign to one reference quaternion, and the result does not depend on the order of the inputs; chaining pairwise slerps does. ## Traps common to both - Skipping the **sign check**, so the result swings the long way round. - Forgetting to normalise the nlerp result, which leaves a quaternion that scales vectors when used in the sandwich product. - Evaluating slerp with no fallback, which produces not-a-number values when the inputs coincide. - Interpolating Euler angles instead, which follows neither arc and varies with the chosen order.
- Why can nlerp of quaternions be trusted to stay on the shortest path between the two orientations?The chord between `q0` and `q1` lies in the plane they span with the origin, so normalising each chord point lands on the great-circle arc between them. With the dot product made non-negative first, that arc is the shorter one. Only the speed along it differs from slerp.
- How would you make nlerp's speed closer to slerp's without paying for an inverse cosine?Remap `t` before the lerp with a small polynomial correction tuned to the dot product, which pulls the middle back and pushes the ends forward. A fitted correction can bring nlerp within a tiny fraction of a degree of slerp at a few extra multiplications. For small angles it is unnecessary.
- Nlerp leaves the shortest arc and cuts a corner through the rotation.
- Nlerp is wrong at the endpoints and the midpoint as well.
- Slerp needs no special handling when the two quaternions are nearly equal.
- Slerp makes the dot-product sign check unnecessary.
- The nlerp result is unit length without normalising.