📜 ⬆️ ⬇️

I twist-twist, I want to confuse: the corners of Euler and Gimbal lock



Hold any finger of your left hand forward. Let's not be shy, no one will laugh at you. This is necessary for an important experiment. Exposed? Now imagine that you - this is your finger (well, nonsense). Turn at a right angle to the right, then upward, and finally to the left. Where did you find yourself? That's right, in the same place, but already on the back.

With some stretch, this is exactly how rotation works with the help of Euler angles. A bit unpredictable and uncomfortable, isn't it? Euler angles have several drawbacks, but there is one particularly bad property due to which you do not want to contact them. His name is Gimbal lock.
')
In Russian, gimbal lock is called differently: hinged lock, axle locking, folding frames. Unfortunately, on requests in the search engine with such keywords, a lot of garbage is given out, and the article on Wikipedia leaves much to be desired, so I will tell you about this phenomenon and suggest how to deal with it.

Attention! Going under the cat you are at risk to break your head.

First, let me remind you what Euler angles are. You probably remember that this is something like a set of three angles of rotation around the axes X, Y and Z? Not certainly in that way. Suppose you want to rotate an object and you have a set of end angles (X: 45 °, Y: 45 °, Z: 45 °). One of the pitfalls of the Euler angles is the need to choose a single order of turns. If you first rotate 45 ° around the X axis, then around Y and finally around Z, you will get the result as in the left half of the picture below. If the order is ZXY, the result will be different, as in the right half.


In fact…
In fact, not just the Euler angles, but the Tate-Brian angles are described above. Euler angles have many confusing variations, in some of which you need to rotate around global axes, in other axes they rotate after each step, in third axes they are always fixed on the object itself and move with it. Everything else adds a different order of turns. If possible, do not use Euler angles.

The choice of the order of turns depends on the place of appearance of the hinge lock. What is it? Take for example this order of turns: ZXY. If the rotation around the X axis is equal to 90 ° or -90 °, then the rotation around Z and Y will “eat” each other and only the stub from the larger rotation will remain. For example (X: 90 °, Y: 90 °, Z: 90 °) will turn into just (X: 90 °, Y: 0 °, Z: 0 °). Attention to the illustration.



You can also substitute (X: 90 °, Y: 130 °, Z: 140 °) or (X: 90 °, Y: 30 °, Z: 40 °), but the result will still be (X: 90 ° , Y: 0 °, Z: 10 °). A little non-intuitive, don't you think? This is all because of the hinge lock. When the rotation around the X axis becomes 90 ° or –90 °, the local rotation axis Y not yet used becomes parallel to the Z axis, but with the opposite direction, so rotation around it conflicts with the previous rotation around Z.

* Bidysch! *

This exploded the heads of particularly impressionable readers. I will explain the same with the arrows.



When the axes coincide, one degree of freedom is lost. This is a hinge lock. You want to make a turn, but you do not have enough axes to implement it.

A hinge lock appears in the middle of the turn hierarchy. If you use the order of XYZ or ZYX, then turning right or left will jam the animation. Since such a turn is more common than, for example, a turn in the direction of the zenith or nadir, many programs use the ZXY sequence. This hierarchy of turns is used in Unity3d, although inside all rotations are still stored in quaternions. What are quaternions? This is better to tell separately. Quaternions and rotation matrices are one way to avoid a hinge lock. There are also tricky algorithms that smoothly bypass the castle side, but this is reflected in the quality of the animation. It is best to use Euler angles only for simple cases: propellers, wheels, pendulums. Sometimes you can change the hierarchy of turns, but then you still have to remember about the lock.

On the links below you can see an interactive demonstration of a hinge lock on the example of a gyroscope. It is much easier to understand the hierarchy of turns and the situation with the lock.

WebGL | Windows | Linux | Mac | Sources on GitHub

Use the mouse to rotate the scene, Esc - exit, the other buttons are indicated on the screen.

For Linux users:
Make the GimbalLock file executable with chmod + x GimbalLock and run it.

Source: https://habr.com/ru/post/183116/


All Articles