Quaternion interpolation with SQUAD: Tangent issue

interpolationquaternionstangent-spaces

For interpolating between keyframes in an animation path I make use of SQUAD(q1,q1_t,q2_t,q2) function.
q1 and q2 beeing the points to interpolate and q1_t and q2_t the tangents in the points respectively.

A,B,C beeing rotations, and rotation direction beeing A -> B -> C then the tangent for B can be calculated
using

$$tang_n = q_n * exp(-\frac{log(q_n^{-1} * q_{n-1}) + log(q_n^{-1} * q_{n+1}) }{4})$$

with A = $q_{n-1}$, B = $q_n$, C = $q_{n+1}$

Tangent formula page 98

Animation path with interpolation looks like this:
enter image description here
with the problematic section marked in red.

Visualizing the rotations anywhere in the proper part of the path
with A = red, B = green, C = blue and B-tangent = yellow:
enter image description here
you can see that the tangent from B is close to the other rotations.

though in the bad part of the path, the visualization looks like this:
enter image description here

The tangent in that section is totally off and thus the interpolation using SQUAD is not clean.

The formula for the tangent can be found in other documents as well, but none mentions any issue with the calculation.

Video

I understand that quaternions are a 4th dimension representation of a rotation by using a rotation axis and an angle. I also understand how to compute the tangents in case of a location path. But the tangent calculation for quaternions is not something I understand and thus can't find the issue with it.

What is the problem with the formula that it works for the most part but has sometimes issues?

Best Answer

As it turned out, it is not an issue with the tangent function, but the function FQuat::Exp and/or FQuat::Log of Unreal Engine that was used to visualize the result. By using functions Log/Exp defined according to Link the problem was solved.