5 ms·
This article incorrectly states that gimbal lock is a property of Euler angles, and that using quaternions prevents it. This is a common misconception. Euler
by OmarShehata 5y ago
This article incorrectly states that gimbal lock is a property of Euler angles, and that using quaternions prevents it.
This is a common misconception.
Euler angles can be used to rotate an object exactly the same way as quaternions do with no gimbal lock. Similarly, you can apply quaternions in such a way that gimbal lock will happen (if you wanted to represent a physical system of gimbals with quaternions, where that is a physical property).
I wrote a short article demonstrating and clarifying this, hope it helps: https://omar-shehata.medium.com/how-to-fix-gimbal-lock-in-n-dimensions-f2f7baec2b5e https://omar-shehata.medium.com/how-to-fix-gimbal-lock-in-n-...
- DecoPerson 5y agoI was hoping your article would example how gimbal lock can occur with quaternions, but from a quick skim I can’t see any such paragraph. Would you mind elaborating?
- OmarShehata 5y agoIt's at the bottom of the "What causes gimbal lock?" section, the final code snippet: ``` rotationAroundX = Quaternion.fromAxisAngle(angle1, Xaxis); rotationAroundY = Quaternion.fromAxisAngle(angle2, Yaxis); rotationAroundZ = Quaternion.fromAxisAngle(angle3, Zaxis); cubeRotation = rotationAroundX * rotationAroundY * rotationAroundZ; ``` Basically, you store 3 quaternions, representing 3 angles, and combine them to get the final rotation. You might say "This is just quaternions emulating Euler angles!" and my answer is, sure. You can say the same about rotation matrices. There's nothing inherent about rotation matrices that makes them susceptible to gimbal lock. You can implement them as representing 3 fixed angles, thus gimbal lock, or you can implement them as accumulating rotations, thus no gimbal lock. Same is true of quaternions. The fact that you can get gimbal lock with quaternions is a feature, not a bug. Quaternions are just one way to describe rotations. Gimbal lock is a natural phenomenon of certain physical rotation systems, and can be described whether you use quaternions, or matrices etc.
- imadr 5y agoThanks for the heads up, I'm going to rephrase the statement about gimbal lock and link you article. And just to be 100% sure, is the approach I'm using the right one: storing a quaternion instead of 3 angles, multiplying, overwriting the rotation value?
- OmarShehata 5y agoYes, exactly! And the idea is, _that's_ how you avoid gimbal lock. It's that implementation of multiplying, and overwriting, which can be done with any system that describes and applies rotation, including Euler angles, rotation matrices, etc.
- greggman3 5y agoSomething else to be aware of http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/ http://number-none.com/product/Understanding%20Slerp,%20Then...
- benrbray 5y agoHowdy 4ur :) Nice article, I'm pretty sure I got dinged once for making this point in a job interview, so good to see you spreading the word.
- OmarShehata 5y agoOh hey!! Always a pleasure running into familiar faces from NG out in the wild :) And that's funny...I had the exact same experience in a job interview...which gave me the extra motivation I needed to finally write that up!
- dahart 5y agoSimilarly, slerp is also not a property of quaternions [1], contrary to the claim in the article, and is usually not implemented inside quaternion libraries using quaternion exponentiation like the article does, but by computing angles explicitly [2], for robustness I believe, and also because slerp is designed for normalized quats, not for general quats with non-unit magnitude. With these two things combined - the two most commonly cited reasons about why to use quaternions (using slerp and avoiding gimbal lock) - what are other reasons to use quaternions? I’m aware that there are moderate compute savings in some cases (a matrix obviously has more degrees of freedom than a rigid orientation). Are there other good reasons to deal in quaternions? There are some reasonable ideas about why not to use them. [3] [1] https://en.wikipedia.org/wiki/Slerp#Geometric_Slerp https://en.wikipedia.org/wiki/Slerp#Geometric_Slerp [2] https://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/index.htm https://www.euclideanspace.com/maths/algebra/realNormedAlgeb... [3] http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/ http://number-none.com/product/Understanding%20Slerp,%20Then...
- jackling 5y agoI believe that even though slerp isn't a property of quaterions and can be retrieve without them, having your orientation represented as a vector is a clean way for the developer to hold the state of an orientation and interpolate it. What's happening under the hood shouldn't matter much, the abstraction in the code using quaterions makes it easier for the developer to interpolate orientations without the worry of gibal locking.
- dllthomas 5y agoOne reason to accumulate into quaternions vs a matrix is that compounded errors can add scaling and shear to a rotation matrix, whereas unit quaternions remain pure rotation (and non-unit quaternions can be trivially normalized).
- dahart 5y agoThat's reasonable, but compound matrix ops can also re-normalized and re-orthogonalized as they go, right? It's easier with a quat, for sure, but does it make up for the general complications with using quats?
- Ono-Sendai 5y agoIf you want to represent different rotations as differential Euler angles, then I think you can say it's a property of Euler angles, or at least linked to them.
- hanche 5y agoHere's an abstract view regarding the inevitability of gimbal lock: The state of a single gimbal is described by an angle. Since angles are mod 360°, that is topologically a circle. The state of three gimbals are then given by three angles. One point on each of three circles is a point on a three-dimensional torus T^3. With no gimbal lock, you get a map from T^3 to SO(3), which is locally a diffeomorphism at every point. For topological reasons, no such map exists: Due to compactness, it would be a cover, but the only covers of SO(3) are SO(3) itself (a single cover) and the three-sphere (unit quaternions, a double cover). And T^3 is distinct from either of these two. Hence gimbal lock is unavoidable with three gimbals. (Four gimbals is a different story, but then you have a redundant dimension to play with.)
- anon_tor_12345 5y agolol i'm a dummy for never realizing that SO(3) isn't homeomorphic (the diffeo part isn't necessary to prove this...) to T^3 (which i naively thought because s in SO(3) seemingly has 3 free parameters). surprise surprise SO(3) is actually homeomorphic to P^3 lol.
- hanche 5y agoYou can drop “seemingly”: SO(3) is indeed tree-dimensional. And SO(3) a.k.a. P^3 has fundamental group Z_2 a.k.a. GF(2), whereas T^3 has fundamental group Z^3, so they are quite different beasts indeed.
- anon_tor_12345 5y agoyea you're right. kudos for explaining it so succinctly.
- zemnmez 5y agoI'm so confused. The article you wrote says that you fix gimbal lock by using quaternion rotation, quote: >To fix gimbal lock, we must avoid modelling this physical gimbal system. > In 3D, instead of using 3 fixed angles that we multiply together to get the final rotation, we will: > 1. Construct a quaternion that describes a rotation around whatever axis we want, and the angle to rotate by.
- jayd16 5y agoAre you simply saying that quaternions can be used to perform the same rotation as the Euler method or are you saying that the rotation information along the Euler axes can also be lost even when using the quaternion method? Said another way, are you conflating gimbal lock the physical property, with gimbal lock the common bug of creating irreversible rotations or is the bug still possible?
- IshKebab 5y agoGreat article. Presumably the reason this confusing exists exists is that people don't want to store full rotation matrices, so their choices are Euler angles or quaternions, and Euler angles guarantee gimbal lock by quaternions allow you to avoid it. Is that right?