I am looking for a way to calculate the value of t of quaternion SLERP by having three quaternions.

Forward direction:

Eigen::Quaternionf q = q1.slerp(t, q2);

where q, q1 and q2 are quaternions from the Eigen library. And t is a float which interpolates between q1 and q2.

I am interested in the backward calculation, where q, q1 and q2 is given and the output is t.

To make it easier all quaternions are normalized and also lying on the same plane which crosses the origin. See the illustration below:

enter image description here

qdoes NOT need to be within q1 and q2.

I found this link here but I don't know how to use that.

  • $\begingroup$ "I found this link here but I don't know how to use that." What do you mean by that? The answer there seems to give a pretty clear equation. What's the difficulty in using it? $\endgroup$ Sep 2, 2020 at 16:54
  • $\begingroup$ @Thomas is this related to your other question? If the quaternions here are all actually 3D vectors, there's a simpler way to solve this using cross products. If it needs to work for full 4D quaternions, it's slightly more involved. $\endgroup$ Sep 2, 2020 at 23:42
  • $\begingroup$ @NathanReed yes it is related to the other question. I think when solving this problem, I am aware of solving the other question too. It doesn't matter if q, q1 and q2 are quaternions or vectors. The only important thing is, that the result t is in both cases equal. $\endgroup$
    – Thomas
    Sep 3, 2020 at 6:25
  • $\begingroup$ @NicolBolas I can't see t as a result in the posted link. also Eigen seems to not have an operator to calculate the log of quaternions. To calculate the logarithm on quaternions is not really the problem, I'll find a way of doing that. $\endgroup$
    – Thomas
    Sep 3, 2020 at 6:33
  • 1
    $\begingroup$ @Thomas: "I can't see t as a result in the posted link." It's the first sentence of the third paragraph. And even if he didn't spell it out, all you need to do is apply basic rules of algebra to the second equation to solve for t. $\endgroup$ Sep 3, 2020 at 13:27

1 Answer 1


We can do this mostly by measuring angles between the quaternions, with a bit of sign flip to get the orientations right. Angles between normalized quaternions are given by the arccos of their dot product (as a 4D vector). $$ t = \frac{\arccos(q_1 \cdot q)}{\arccos(q_1 \cdot q_2)} \ \text{sign}\bigl(q \cdot [q_2 - (q_1 \cdot q_2) q_1]\bigr) $$ The first factor is measuring the angle from $q_1$ to $q$ as a fraction of the angle from $q_1$ to $q_2$. This ensures that $t$ will be 0 at $q_1$ and 1 at $q_2$. The other factor ensures that $t$ increases as you move from $q_1$ toward $q_2$ and goes negative on the other side. The quantity in brackets is the projection of $q_2$ on the (hyper)plane perpendicular to $q_1$, then we're dotting $q$ with that to decide which side of the circle we're on.

Note that the point where $t$ swaps from negative to positive will be the point opposite $q_1$ on the circle—not a point centered across from $q_1$ and $q_2$ as your diagram has it.

(Also, it's worth noting that this boils down to essentially the same thing as the logarithm solution in the other answer. Their factor $\check p/\|\check p\|$ corresponds to our sign factor: all the quaternions in the problem are in the same plane and so will have $\check p$ along the same axis; the only thing that can differ between the normalized $\check p$s is the sign.)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.