Quaternion distance

I am using quaternions to represent orientation as a rotational offset from a global coordinate frame.

Is it correct in thinking that quaternion distance gives a metric that defines the closeness of two orientations? i.e. similar orientations give low distances, and dissimilar orientations give high distances.

Does zero distance mean that the orientations are exactly the same?

This seems obvious, but I want to ensure that there are no subtleties that get in the way of logic.


Solution 1:

First, I assume that you're using unit quaternions, i.e. quaternions $a+b\,\textbf{i}+c\,\textbf{j}+d\,\textbf{k}$ that satisfy $a^2 + b^2 + c^2 + d^2 = 1$. If not, you'll want to scale your quaternions before computing distance.

Distance between quaternions will correspond roughly to distance between orientations as long as the quaternions are fairly close to each other. However, if you're comparing quaternions globally, you should remember that $q$ and $-q$ always represent the same orientation, even though the distance between them is $2$.

There are better ways to compute the closeness of two orientations that avoid this problem. For example, the angle $\theta$ of rotation required to get from one orientation to another is given by the formula $$ \theta \;=\; \cos^{-1}\bigl(2\langle q_1,q_2\rangle^2 -1\bigr) $$ where $\langle q_1,q_2\rangle$ denotes the inner product of the corresponding quaternions: $$ \langle a_1 +b_1 \textbf{i} + c_1 \textbf{j} + d_1 \textbf{k},\; a_2 + b_2 \textbf{i} + c_2 \textbf{j} + d_2 \textbf{k}\rangle \;=\; a_1a_2 + b_1b_2 + c_1 c_2 + d_1d_2. $$ (This formula follows from the double-angle formula for cosine, together with the fact that the angle between orientations is precisely twice the angle between unit quaternions.)

If you want a notion of distance that can be computed without trig functions, the quantity $$ d(q_1,q_2) \;=\; 1 - \langle q_1,q_2\rangle^2 $$ is equal to $(1-\cos\theta)/2$, and gives a rough estimate of the distance. In particular, it gives $0$ whenever the quaternions represent the same orientation, and it gives $1$ whenever the two orientations are $180^\circ$ apart.