26
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ The quaternions are a normed vector space, thus $\|x-y\|=0$ implies $x-y=0$. That is, distance zero implies $x=y$. Any norm induces a metric, $d(x,y)=\|x-y\|$. So your question is, for quaterions $q_1,q_2$ which are close, is $q_1uq_1^{-1}$ close to $q_2uq_2^{-1}$ for vector $u \in \mathbb{R}^3$? I'm unsure how to answer this part of the question. $\endgroup$ – dls Dec 10 '11 at 1:29
50
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ Thanks Jim, that makes things a lot clearer. $\endgroup$ – Josh Dec 10 '11 at 5:09
  • 1
    $\begingroup$ Should have been: $d(q_1,q_2) = 2\arccos(<q_1,q_2>)$ $\endgroup$ – Alec Jacobson Jan 9 '14 at 17:01
  • 1
    $\begingroup$ @mangledorf The formula I give for $\theta$ is correct in all cases. The formula $\theta = 2 \arccos(\langle q_1,q_2\rangle)$ doesn't work when $\langle q_1,q_2\rangle < 0$, although $\theta = 2\arccos(|\langle q_1q_2\rangle |)$ would be fine. $\endgroup$ – Jim Belk Jan 9 '14 at 17:56
  • 1
    $\begingroup$ @mangledorf Something like that, although it isn't possible to separate the two sheets of the cover. But $\langle q_1,q_2\rangle<0$ corresponds to the case where $-q_2$ is "closer" to $q_1$ than $q_2$ is. $\endgroup$ – Jim Belk Jan 9 '14 at 23:58
  • 3
    $\begingroup$ According to ["Metrics for 3D rotations: Comparison and Analysis"][1] which compares a number of metrics, you might want to use the geodesic distance of the normed quaternions, since these lie on the unit 3-sphere (the euclidean distance is not appropriate there). It so happens that it is exactly the formula for $\theta$ that @JimBelk mentions. [1]: dx.doi.org/10.1007/s10851-009-0161-2 $\endgroup$ – yannick Apr 14 '14 at 9:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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