25
$\begingroup$

I suspect this is a bit basic for mathoverflow, seeing I'm still just an undergraduate

I've been playing around with quaternions as means to eliminate the gimbal lock. From what I understand, one place the gimbal lock occurs is when you rotate $\frac{\pi}{2}$ around the y-axis. If I create two rotation matrices, $R_{1}$ rotates first $\phi$ around x-axis and $\frac{\pi}{2}$ around the y-axis, while $R_{2}$ rotates first $\frac{\pi}{2}$ around the y-axis and then $\theta$ around the z-axis.

$\begin{equation} R_{1} = R_{z}(0) R_{y}(\frac{\pi}{2}) R_{x}(\phi) \\ = \begin{bmatrix} 0 & 0 & 1 \\ 0 & 1 & 0 \\ -1 & 0 & 0 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & \cos(\phi) & -\sin(\phi) \\ 0 & \sin(\phi) & \cos(\phi) \end{bmatrix} \\ = \begin{bmatrix} 0 & \sin(\phi) & \cos(\phi) \\ 0 & \cos(\phi) & -\sin(\phi) \\ -1 & 0 & 0 \end{bmatrix}, \end{equation}$

$\begin{equation} R_{2} = R_{z}(\theta) R_{y}(\frac{\pi}{2}) R_{x}(0) \\ = \begin{bmatrix} \cos(\theta) & -\sin(\theta) & 0 \\ \sin(\theta) & \cos(\theta) & 0 \\ 0 & 0 & 1 \\ \end{bmatrix} \begin{bmatrix} 0 & 0 & 1 \\ 0 & 1 & 0 \\ -1 & 0 & 0 \end{bmatrix} \\ = \begin{bmatrix} 0 & -\sin(\theta) & \cos(\theta) \\ 0 & \cos(\theta) & \sin(\theta) \\ -1 & 0 & 0 \end{bmatrix}. \end{equation} $

Since $R_{1} = R_{2}^{-1} \Rightarrow R_{1}(\theta) = R_{2}(-\theta)$, we've lost a degree of freedom. Which is what I expect.

From what I understand, if I perform the same rotations using quaternions, I should be avoiding the gimbal lock?

$ Q_{1} = Q_{z}(0) \times Q_{y}(\frac{\pi}{2}) \times Q_{x}(\theta) = (1, 0, 0, 0) \times (\frac{1}{\sqrt(2)}, 0, \frac{1}{\sqrt(2)}, 0) \times (\cos\frac{\theta}{2}, \sin\frac{\theta}{2}, 0, 0)\\ = \frac{1}{\sqrt(2)}(\cos\frac{\theta}{2}, \sin\frac{\theta}{2}, \cos\frac{\theta}{2}, -\sin\frac{\theta}{2})$

$ Q_{2} = Q_{z}(\phi) \times Q_{y}(\frac{\pi}{2}) \times Q_{x}(0) = (\cos\frac{\phi}{2}, 0, 0, \sin\frac{\phi}{2}) \times (\frac{1}{\sqrt(2)}, 0, \frac{1}{\sqrt(2)}, 0) \times (1, 0, 0, 0) \\ = \frac{1}{\sqrt(2)}(\cos\frac{\phi}{2}, -\sin\frac{\phi}{2}, \cos\frac{\phi}{2}, \sin\frac{\phi}{2})$

By setting $\phi = -\theta$, $Q_{2}$ becomes

$ Q_{2} = \frac{1}{\sqrt(2)}(\cos\frac{-\theta}{2}, -\sin\frac{-\theta}{2}, \cos\frac{-\theta}{2}, \sin\frac{-\theta}{2})$ which due to trig properies becomes $ Q_{2} = \frac{1}{\sqrt(2)}(\cos\frac{\theta}{2}, \sin\frac{\theta}{2}, \cos\frac{\theta}{2}, -\sin\frac{\theta}{2})$

Which means that $Q_{1}$ and $Q_{2}$ rotates around the same axis only in the oppsite direction, and we've lost a degree of freedom (??). Am I missing something fundamental?

$\endgroup$
  • 6
    $\begingroup$ While a lot of people will say to ask this on MSE, I would personally like to see the question answered here. $\endgroup$ – Steven Gubkin May 3 '12 at 19:12
59
$\begingroup$

There's no paradox here: you did the same calculation in two different ways and got the same answer, as you should. The issue is how to think about gimbal lock.

How should you represent a rotation in three dimensions? You can try using Euler angles to represent it using three rotation angles, but there's something fishy about this. That naturally parametrizes a three-dimensional torus, but the rotation group is not a torus (rather, it's a projective space). It doesn't even have a torus as a covering space, but rather a 3-sphere. So the problem is that the naive coordinates just don't give the right topology, and therefore something must go wrong in degenerate cases to fix the topology. Gimbal lock is essentially a name for what goes wrong.

When people say quaternions avoid gimbal lock, they mean the unit quaternions naturally form a 3-sphere, so there are no topology issues and they give a beautiful double cover of the rotation group (via a very simple map). Keeping track of a unit quaternion is fundamentally a more natural way to describe a rotation than keeping track of three Euler angles.

On the other hand, if you describe your quaternion via Euler angles, then gimbal lock shows up again, not in the quaternions themselves but in your coordinate system for them. That's what you are seeing in your calculations: you are doing a standard calculation to see the effects of gimbal lock, and then redoing the same calculation using quaternions.

Some explanations of gimbal lock don't distinguish clearly between the underlying geometry/topology and the choice of coordinates, which has always annoyed me, since that's essential for understanding what's going on mathematically.

$\endgroup$
  • 2
    $\begingroup$ " but the rotation group is not a torus (rather, it's a projective space). " Could you explain why / give a counter example or something? I mean, this rotation group seems like a country with 3 degrees of freedom, bounded, and where there are "non trivial and non reductible ways to make a tour": a (path from 0 to a) 360 degree rotation seems hard to cut in parts. A good candidate for a 3-torus I thought. But clearly what you say implies I was mistaken: can you point a continuous deformation from the 360 disco turnaround to zero? Thank you! $\endgroup$ – Billy Nov 15 '16 at 8:35
  • 5
    $\begingroup$ There's a beautiful example that's often called the belt trick or plate trick, which gives a continuous deformation from a 720 degree turnaround to zero. Hold your hand out in front of you, palm facing up, and start rotating your palm to the right while always keeping it facing up. It will be awkward, but you'll be able to rotate your hand a full 360 degrees, which will leave your arm thoroughly twisted. Now your arm traces out a nontrivial loop in the rotation group. If you keep your hand and body in the same orientation, you can't untwist your arm, because the loop is not contractible. $\endgroup$ – Henry Cohn Nov 15 '16 at 13:43
  • 5
    $\begingroup$ So far this does not distinguish the rotation group from a torus, but the wonderful part is what happens if you do it twice. What if you continue rotation your hand another 360 degrees in the same direction? Instead of leaving your arm twice as twisted, it actually untwists your arm and returns it to its original state. (This is really worth trying.) In other words, we have found a loop that is not contractible but becomes contractible if doubled. This cannot occur in the torus, but the fundamental group of $\mathbb{R}\mathbb{P}^3$ is $\mathbb{Z}/2\mathbb{Z}$, so it fits perfectly with that. $\endgroup$ – Henry Cohn Nov 15 '16 at 13:51
  • $\begingroup$ Very good tangible explanation! :) $\endgroup$ – paul garrett Apr 25 at 17:52

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.