The gimbal lock shows up in my quaternions - MathOverflow most recent 30 from http://mathoverflow.net 2013-05-21T21:42:33Z http://mathoverflow.net/feeds/question/95902 http://www.creativecommons.org/licenses/by-nc/2.5/rdf http://mathoverflow.net/questions/95902/the-gimbal-lock-shows-up-in-my-quaternions The gimbal lock shows up in my quaternions Knut Saua Mathiesen 2012-05-03T17:53:55Z 2012-05-03T19:42:22Z <p>I suspect this is a bit basic for mathoverflow, seeing I'm still just an undergraduate </p> <p>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.</p> <p><code>$$$R_{1} = R_{z}(0) R_{y}(\frac{\pi}{2}) R_{x}(\phi) \\ = \begin{bmatrix} 0 &amp; 0 &amp; 1 \\ 0 &amp; 1 &amp; 0 \\ -1 &amp; 0 &amp; 0 \end{bmatrix} \begin{bmatrix} 1 &amp; 0 &amp; 0 \\ 0 &amp; \cos(\phi) &amp; -\sin(\phi) \\ 0 &amp; \sin(\phi) &amp; \cos(\phi) \end{bmatrix} \\ = \begin{bmatrix} 0 &amp; \sin(\phi) &amp; \cos(\phi) \\ 0 &amp; \cos(\phi) &amp; -\sin(\phi) \\ -1 &amp; 0 &amp; 0 \end{bmatrix},$$$</code></p> <p><code>$$$R_{2} = R_{z}(\theta) R_{y}(\frac{\pi}{2}) R_{x}(0) \\ = \begin{bmatrix} \cos(\theta) &amp; -\sin(\theta) &amp; 0 \\ \sin(\theta) &amp; \cos(\theta) &amp; 0 \\ 0 &amp; 0 &amp; 1 \\ \end{bmatrix} \begin{bmatrix} 0 &amp; 0 &amp; 1 \\ 0 &amp; 1 &amp; 0 \\ -1 &amp; 0 &amp; 0 \end{bmatrix} \\ = \begin{bmatrix} 0 &amp; -\sin(\theta) &amp; \cos(\theta) \\ 0 &amp; \cos(\theta) &amp; \sin(\theta) \\ -1 &amp; 0 &amp; 0 \end{bmatrix}.$$$</code></p> <p>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.</p> <p>From what I understand, if I perform the same rotations using quaternions, I should be avoiding the gimbal lock?</p> <p><code>$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})$</code></p> <p><code>$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})$</code></p> <p>By setting $\phi = -\theta$, $Q_{2}$ becomes</p> <p><code>$Q_{2} = \frac{1}{\sqrt(2)}(\cos\frac{-\theta}{2}, -\sin\frac{-\theta}{2}, \cos\frac{-\theta}{2}, \sin\frac{-\theta}{2})$</code> which due to trig properies becomes <code>$Q_{2} = \frac{1}{\sqrt(2)}(\cos\frac{\theta}{2}, \sin\frac{\theta}{2}, \cos\frac{\theta}{2}, -\sin\frac{\theta}{2})$</code></p> <p>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?</p> http://mathoverflow.net/questions/95902/the-gimbal-lock-shows-up-in-my-quaternions/95908#95908 Answer by Henry Cohn for The gimbal lock shows up in my quaternions Henry Cohn 2012-05-03T19:42:22Z 2012-05-03T19:42:22Z <p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p> <p>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.</p>