Euler angles - you probably remember that this is something like a set of three angles of rotation about the axes X, Y and Z? Not exactly.

Suppose you want to rotate an object, and you have a set of finite angles (X: 45 °, Y: 45 °, Z: 45 °). One of the pitfalls of the Euler angles - the need to choose some of the same order of turns. If the first turn 45 ° around the axis X,

then around Y

and at the end Z, then obtain the result in the left half of the picture below. If the order is ZXY, then the result will be different, as on the right half.

In fact, not only the above described Euler angles, it's the angles Tate - Bryan. Euler angles are many confusing variations, some of which need to be rotated around the global axes, in other axes are rotated after each step in the third axis is always fixed on the object and move with it. Everything else is added to a different order of turns. If you can - do not use the Euler angles.

The choice of the order of rotations depends on the place the appearance of gimbal lock. What is it? Take for example this procedure turns: ZXY. If the rotation about the X axis will be equal to 90 ° or -90 °, then the rotation about the Z and Y 'is' one another and there will be only a stub of the larger of rotations. For example (X: 90 °, Y: 90 °, Z: 90 °) in a turn (X: 90 °, Y: 0 °, Z: 0 °). Attention to the illustrations.

Can also be substituted (X: 90 °, X: 130 °, Z: 140 °), or (X: 90 °, Y: 30 °, Z: 40 °), but the result will still be obtained (X: 90 °, Y: 0 °, Z: 10 °). Bit is not intuitive, do not you think? This is all due to gimbal lock. When the rotation around the X axis is equal to 90 ° or -90 °, may not use the local rotation axis Y becomes parallel to the axis Z, but with the opposite direction, so the rotation around it comes into conflict with the previous rotation around Z.

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

Joint lock appears in the middle of the hierarchy turns. If you use the procedure XYZ or ZYX, then turn to the right or to the left will jam animation. Since such a turn is much more common than, for example, turn towards the zenith or nadir, in many programs use a sequence ZXY. This hierarchy of turns used in Unity3d, though everything inside rotation still stored in quaternions. What are quaternions? This is better to tell apart. Quaternions and rotation matrix is one way to avoid gimbal lock. There are also clever algorithms that seamlessly bypass the lock side, but it affects the quality of the animation. It is best to use the Euler angles only for simple cases: propellers, wheels, pendulums. Sometimes it is possible to change the hierarchy of turns, but then still have to remember about the lock.

View a live demo of gimbal lock on the example of the gyroscope. With him understand the hierarchy and the situation turns to the castle much easier.

Unity Web Player / Windows / Linux / Mac

All data posted on the site represents accessible information that can be browsed and downloaded for free from the web.

https://habrahabr.ru/post/183116/

User replies