For some reason, I've been thinking about quaternion interpolation and the different types: slerp, nlerp, exp-map, modified nlerp.
I know Casey used to be an expert at this (probably still is) and says to just use nlerp (normalized linear interpolation) for quaternions rather than the "proper" slerp (spherical linear interpolation) if that much accuracy is not needed.
I was wondering if anyone uses a modified nlerp instead to be a middle ground between nlerp and slerp? And by that, I mean change the parameter of t depending on the input.
| Quat nlerp(Quat a, Quat b, float t)
{
Quat r = a*t + b*(1.0f - t); // (or a + (b-a)*t)
return r;
}
Quat mod_nlerp(Quat a, Quat b, float t)
{
float new_t = some_func(a, b, t);
return nlerp(a, b, new_t);
}
|
The problem with nlerp and quaternions is that quaternions actually lie on the surface on the 4d 3-sphere with a radius of the magnitude of the quaternion. This means that the "true" path is along a geodesic on the surface of the 3-sphere meaning that its path is actually longer than tunnelling to the next point. Thus, as the interpolation parameter, t, varies, the velocity of the transform is not constant. To lessen this, you can change how t varies with respect to the two input quaternions.
By expanding the equations for geometric interpolation, the modified version of t is shown to be:
t' ≈ t + θ^2 / 6 (-2t^3 + 3t^2 - t) + O(θ^4)
This a very good approximation to what is actually needed however, it does require knowing the angle between the two quaternions, θ, beforehand. One of the advantages of not using slerp is to avoid/minimize using any operations other than basic floating point ops (e.g. not using sqrt, cos, arccos, sin, etc.).
Luckily, cosθ is very easy to calculate as it the inner/dot product of the two quaternions cosθ = dot(q_0, q_1). Using this, and the approximation of cosθ ≈ 1 - 0.5θ^2, the new modified parameter is as follows:
t' ≈ t + (1 - cosθ) / 3 (-2t^3 + 3t^2 - t) = t + (1 - q_0.q_1) / 3 (-2t^3 + 3t^2 - t).
This approximate is not as good as the previous approximation but it now removes the need for any trigonometric functions (and is still pretty close)!
The higher order terms of the Taylor series cannot be used, O(θ^4), as they _require_ the use of either sqrt or trigonometric functions and defeating the point of this approximation. And the θ^4 term is extremely small too (1/360).
This approximation does have the advantage that at t={0, 0.5, 1}, the values are identical to that of slerp and nlerp.
I was wondering if anyone uses something like this or if it is even used at all or even needed?
Regards,
Bill