Choose between quaternion ambiguity with respect to a reference quaternion

1.1k Views Asked by At

I'm here to ask for a simple question about unit quaternions. I have a quaternion, say $q_1$. Now, I would like to choose between $q_2$ and $-q_2$ (that represent the same rotation), by choosing the one that has the "smallest distance" to $q_1$. I can give an example of my question, then it is clearer to everyone. Actually, $q_1$ and $q_2$ is the same quaternion in two time instants. Since in my computations I have functions of the single elements of $q_2$, it is important the sign of those elements. Then, I would like the quaternion that is "more similar to" $q_2$. Roughly speaking, if my quaternion is [1 0 0 0] and then I have [0.99 0 0 0.1411] and [-0.99 0 0 -0.1411], I would like to choose the first one.

I have search in the web without a clear answer to this question, even because there can be cases in which the difference is not so evident as in the example that I provided above. Many thanks in advance for your reply.

Regards, Neostek

1

There are 1 best solutions below

0
On

The product between two quaternions $q_1=(a_1,\vec{v}_1)$ and $q_2=(a_2,\vec{v}_2)$ is given by

$$q_1q_2=(a_1a_2-\vec{v}_1\cdot\vec{v}_2,a_1\vec{v}_2+a_2\vec{v}_1+\vec{v}_1\times\vec{v}_2).$$

Therefore, the inner product between $q_1$ and $q_2$ as $\mbox{4D}$ vectors in $\mathbb{R}^4$ is given by

$$\mathrm{Re}(q_1q_2^*)=a_1a_2+\vec{v}_1\cdot\vec{v}_2=|q_1||q_2|\cos\theta,$$

where $\,|q_1|=|q_2|=1\,$ for unit quaternions. Therefore, the inner product $\,\mathrm{Re}(q_1q_2^*)=\cos\theta\,$ gives the cosine of the angle $\,\theta\,$ between $\,q_1\,$ and $\,q_2\,$ as vectors in $\,\mathbb{R}^4$. You can then make the choice based on which angle $\,\theta\,$ is smaller. One can prove that the law of cosine

$$|q_1-q_2|^2=|q_1|^2+|q_2|^2-2\,\mathrm{Re}(q_1q_2^*)$$

applies to quaternions as well. Therefore the angle reflects the distance for unit quaternions. Note that $\,(q_1q_2^*)^*=q_2q_1^*\,$ (not $\,q_1^*q_2\,$ in general because quaternion product does not commute).