<p>A <code>gimbal</code> is a pivoted support that allows you to rotate around one axis. Now it so happens that Euler rotations* work like a set of 3 gimbals attached to each other, one rotation builds upon the next (or previous/whole stack if your inclined to model it that way).</p>
<p><a href="https://i.sstatic.net/9Bkct.gif" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9Bkct.gif" alt="enter image description here" /></a></p>
<p><strong>Image 1</strong>: Rotation is like a gimbal. <a href="http://tf3dm.com/3d-model/fa-22-raptor-86148.html" rel="nofollow noreferrer">Model</a> using <em>yxz</em> rotation (z=blue, x= red and y=green) in a physical 3 axis gimbal structure.</p>
<p>A <code>gimbal lock</code> happens when you turn 2 or 3 of the successive gimbals and they align onto a plane. You succeed in erasing one direction since the angles both operate same same direction.</p>
<p><a href="https://i.sstatic.net/1pCtJ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1pCtJ.png" alt="enter image description here" /></a></p>
<p><strong>Image 2</strong>: Rotation direction lost because 2 of the rotations overlap.</p>
<p>The only way out is to unwind the structure. Although this is the lock, problems due to diminishing possibilities to turn start earlier than the lock itself.</p>
<h3>A more in depth look at things</h3>
<p>Now this is where most people stop thinking about the issue and move on with their life. They just conclude that Euler angles are somehow broken. This is also where a lot of misunderstandings happen so it's worth investigating the matter slightly further than what causes gimbal lock.</p>
<p>It is important to understand that this is <em>only</em> problematic if you <code>interpolate</code> in Euler angles**! In a real physical gimbal this is given - you have no other choice. In computer graphics you have many other choices, from normalized matrix, axis angle or quaternion interpolation. Gimbal lock has a much more dramatic implication to designing control systems than it has to 3d graphics. Which is why a mechanical engineer for example will have a very different take on gimbal locking.</p>
<p>You don't have to give up using Euler angles to get rid of gimbal locking, just stop interpolating values in Euler angles. Of course, this means that you can now no longer drive a rotation by doing direct manipulation of one of the channels. But as long as you key the 3 angles simultaneously you have no problems and you can internally convert your interpolation target to something that has less problems.</p>
<p>Using Euler angles is just simply more intuitive to think in most cases. And indeed Euler never claimed it was good for interpolating but just that it can model all possible space orientations. So Euler angles are just fine for setting orientations like they were meant to do. Also incidentally Euler angles have the benefit of being able to model multi turn rotations which will not happen sanely for the other representations.</p>
<h3>Problems and how to circumvent them</h3>
<p>The fact of the matter is that interpolating in Euler angle space is a bad idea, in general and affects you way before you come close to a true gimbal lock. For this reason NASA lunar orbiter would warn of gimbal lock when you come close to a 70-80 degree angle on a single gimbal's turn. So be aware that people do not necessarily talk of just the actual locking condition when they talk of a gimbal lock. Even worse some people blame all their rotation problems on gimbal locking.</p>
<p>Euler rotation is only safe if you rotate primarily one angle and shallow amounts on the other 2 rotations, which is quite common admittedly. This works fine for describing movement of a commercial airliner, a car etc. But not so well for a jet fighter or an acrobatics plane doing complex air maneuvers. What happens is the rotations start to interfere with each other and you get a weird wobble instead of moving straight from one position to the next.</p>
<p>To fix the wobble problem in shallow cases just swap the rotation order so that the big rotation gets applied on the other rotations. If you need to use more complex rotations then either switch over to other interpolation methods or add even more rotation links to your gimbal (which is a good stopgap measure for cases where you cannot do the switch in a timely manner).</p>
<hr />
<p>* To be exact most of the time people do not actually use Euler angles but Tait–Bryan angles. Which are nearly the same thing only Euler insisted on repeating the same axis, not very important distinction but good to know if you ever speak to an academic.</p>
<p>** Oh well, if you use Euler–Lagrange equation it won't matter.</p>

CC BY-SA 4.0
2019-11-08T07:58:42.330Z
finally someone saying that gimbal lock is not due to euler angles. Saying that quaternions aren't affected by gimbal lock for example is silly, since when you express a rotation sequence with them (or with rotation matrices for that matter) you get the same exact problem (because both representations are expressed in terms of euler angles). Is the ability to do spherical interpolation from one orientation to another that is correct.
Luca
CC BY-SA 4.0
2016-12-30T22:12:50.373Z
2021-10-25T07:45:46.210Z
2021-10-25T07:45:46.210Z
joojaa
<p>Rotations in 3D are normally done with matrices. The xyz Euler angles can be converted to matrices so that it can be used in the rotation.
That is where something called rotation order comes in.
Basically it says in what order you rotate the object.
First you rotate the object around the x axis, then the y axis and lastly the z axis for example.</p>

<p>This means that when you rotate the object around the x axis first, you change the way the y axis and z axis rotate.
Of course this changes depending on the rotation order.</p>

<p>This GIF shows how changing one axis value can change the others, but it doesn't work that way for everything.</p>

<p><img src="https://i.giphy.com/3oz8xXJ5NB2owg5V16.gif" alt="gimbal lock"></p>

<p>Here you can also see at the end that I add in that gimbal lock.
This is where I lose one axis of rotation.</p>

<p>This could be fixed by changing the rotation order to an order, where it doesn't break the way it should work.
It could also be fixed by not using Euler angles but Euler angles are handy and simple in 3D animation.</p>

<p>In 3D animation it could lead to weird rotations since the values of the rotations have to be changed a lot to get a certain rotation that you want.
If you would look at the xyz Euler angle values in a graph, you would see spikes because of that.
This could lead to weird interpolation of the keyframes and a weird end result.</p>

<p>If you would like to read more about the math behind it, I would recommend reading about rotation matrices in 3D.
<a href="https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations" rel="noreferrer">https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations</a></p>

<p>A little extra explanation for the animation:
Rotation in this case is around axis (shown as circles) and by rotating on one axis, you rotate the other axis. The consequence is that with a normal rotation sphere (the sphere in the animation, but then without the axis being rotated) in the animation, you don't see these axis being rotated. If you get a gimbal lock, one axis is the same as another one, but with a normal rotation sphere it still tries to rotate as if that axis wasn't the same as another one, this means that it uses weird values to get to that rotation and this can make an animation look weird.</p>

<p>I hope this helps!</p>

CC BY-SA 4.0
2022-04-05T00:18:44.617Z
`This means that when you rotate the object around the x axis first, you change the way the y axis and z axis rotate`
so, other axis will have the same situation, and there will be not axis aligned
Liu Hao
CC BY-SA 3.0
2016-12-30T12:11:07.313Z
I can't tell from the animation what the specific causes and consequences of the gimbal lock are. Could you explain more about what happens and whether it is reversible?
trichoplax is on Codidact now
CC BY-SA 3.0
2016-12-30T14:58:35.853Z
Oh sorry, rotation in this case is around axis (shown as circles) and by rotating on one axis, you rotate the other axis. The consequence is that with normal rotation sphere (the sphere in the animation) in animation, you don't see these axis being rotated, so if you get a gimbal lock, one axis is the same as another one, but with a normal rotation sphere it still tries to rotate as if that axis wasn't the same as another one, this means that it uses weird values to get to that rotation. I thought that the full post made that clear and that Ankit had some knowledge about it, @trichoplax
bram0101
CC BY-SA 3.0
2016-12-30T15:16:59.590Z
For me, the extra explanation in your comment makes a big difference, so it might be worth editing it into the answer for future readers (comments aren't guaranteed to stay around).
trichoplax is on Codidact now
CC BY-SA 3.0
2016-12-30T19:32:16.730Z
Gimbal lock has nothing to do with matrices.
joojaa
CC BY-SA 3.0
2016-12-30T22:18:29.197Z
The way I see it, is that knowing a little bit about how the rotation matrix is made from Euler angles can be useful to understanding Gimbal locking @joojaa  But you do have a point.
bram0101
CC BY-SA 3.0
2016-12-30T22:27:50.870Z
@bram0101 sure. Or you can actually not think so abstractly and think of it as actual physical 3 axis gimbal
joojaa
CC BY-SA 3.0
2016-12-31T05:42:47.707Z
" The xyz Euler angles can be converted to matrices so that it can be used in the rotation. That is where something called rotation order comes in " cleared my confusion. Thanks.
videogamechef
CC BY-SA 3.0
2016-12-30T10:46:21.203Z
2016-12-30T16:06:55.983Z
2017-03-10T09:42:35.423Z
bram0101
<p>I was studying about Euler angles and I came across the problem gimbal lock which can occur by using Euler angles. In gimbal lock we lose one axis of rotation. </p>

<p>But how? And when does it happen? On what conditions? </p>

<p>All I know about Euler angles is that rotation always occurs about the object axes not upright axes (axes whose orientation is always the same as the world axes). And the object axes will remain perpendicular to each other in each rotation. </p>

<p>Could someone use Euler angles and show me how to get to that point of gimbal lock?</p>

<p>How can it affect animations?</p>

<rendering><3d><animation><mathematics>
How to achieve gimbal lock with Euler angles?
videogamechef
# How to achieve gimbal lock with Euler angles?

(Asked by: username_0 on 2016-12-29)

I was studying about Euler angles and I came across the problem gimbal lock which can occur by using Euler angles. In gimbal lock we lose one axis of rotation.

But how? And when does it happen? On what conditions?

All I know about Euler angles is that rotation always occurs about the object axes not upright axes (axes whose orientation is always the same as the world axes). And the object axes will remain perpendicular to each other in each rotation.

Could someone use Euler angles and show me how to get to that point of gimbal lock?

How can it affect animations?

**Tags:** rendering, 3d, animation, mathematics


---

## 2 answers

### Answer by username_3 on 2016-12-30. Score: 12 | Accepted answer

Rotations in 3D are normally done with matrices. The xyz Euler angles can be converted to matrices so that it can be used in the rotation.
That is where something called rotation order comes in.
Basically it says in what order you rotate the object.
First you rotate the object around the x axis, then the y axis and lastly the z axis for example.

This means that when you rotate the object around the x axis first, you change the way the y axis and z axis rotate.
Of course this changes depending on the rotation order.

This GIF shows how changing one axis value can change the others, but it doesn't work that way for everything.

![gimbal lock](https://i.giphy.com/3oz8xXJ5NB2owg5V16.gif)

Here you can also see at the end that I add in that gimbal lock.
This is where I lose one axis of rotation.

This could be fixed by changing the rotation order to an order, where it doesn't break the way it should work.
It could also be fixed by not using Euler angles but Euler angles are handy and simple in 3D animation.

In 3D animation it could lead to weird rotations since the values of the rotations have to be changed a lot to get a certain rotation that you want.
If you would look at the xyz Euler angle values in a graph, you would see spikes because of that.
This could lead to weird interpolation of the keyframes and a weird end result.

If you would like to read more about the math behind it, I would recommend reading about rotation matrices in 3D.
<https://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations>

A little extra explanation for the animation:
Rotation in this case is around axis (shown as circles) and by rotating on one axis, you rotate the other axis. The consequence is that with a normal rotation sphere (the sphere in the animation, but then without the axis being rotated) in the animation, you don't see these axis being rotated. If you get a gimbal lock, one axis is the same as another one, but with a normal rotation sphere it still tries to rotate as if that axis wasn't the same as another one, this means that it uses weird values to get to that rotation and this can make an animation look weird.

I hope this helps!

> **Comments:**
> **username_5**: I can't tell from the animation what the specific causes and consequences of the gimbal lock are. Could you explain more about what happens and whether it is reversible?  
> **username_3**: Oh sorry, rotation in this case is around axis (shown as circles) and by rotating on one axis, you rotate the other axis. The consequence is that with normal rotation sphere (the sphere in the animation) in animation, you don't see these axis being rotated, so if you get a gimbal lock, one axis is the same as another one, but with a normal rotation sphere it still tries to rotate as if that axis wasn't the same as another one, this means that it uses weird values to get to that rotation. I thought that the full post made that clear and that Ankit had some knowledge about it, @username_5  
> **username_5**: For me, the extra explanation in your comment makes a big difference, so it might be worth editing it into the answer for future readers (comments aren't guaranteed to stay around).  
> **username_1**: Gimbal lock has nothing to do with matrices.  
> **username_3**: The way I see it, is that knowing a little bit about how the rotation matrix is made from Euler angles can be useful to understanding Gimbal locking @username_1  But you do have a point.  
> **username_1**: @username_3 sure. Or you can actually not think so abstractly and think of it as actual physical 3 axis gimbal  
> **username_0**: " The xyz Euler angles can be converted to matrices so that it can be used in the rotation. That is where something called rotation order comes in " cleared my confusion. Thanks.  
> **username_4**: `This means that when you rotate the object around the x axis first, you change the way the y axis and z axis rotate` so, other axis will have the same situation, and there will be not axis aligned  

---

### Answer by username_1 on 2016-12-30. Score: 14

A `gimbal` is a pivoted support that allows you to rotate around one axis. Now it so happens that Euler rotations\* work like a set of 3 gimbals attached to each other, one rotation builds upon the next (or previous/whole stack if your inclined to model it that way).

[![enter image description here](https://i.sstatic.net/9Bkct.gif)](https://i.sstatic.net/9Bkct.gif)

**Image 1**: Rotation is like a gimbal. [Model](http://tf3dm.com/3d-model/fa-22-raptor-86148.html) using *yxz* rotation (z=blue, x= red and y=green) in a physical 3 axis gimbal structure.

A `gimbal lock` happens when you turn 2 or 3 of the successive gimbals and they align onto a plane. You succeed in erasing one direction since the angles both operate same same direction.

[![enter image description here](https://i.sstatic.net/1pCtJ.png)](https://i.sstatic.net/1pCtJ.png)

**Image 2**: Rotation direction lost because 2 of the rotations overlap.

The only way out is to unwind the structure. Although this is the lock, problems due to diminishing possibilities to turn start earlier than the lock itself.

### A more in depth look at things

Now this is where most people stop thinking about the issue and move on with their life. They just conclude that Euler angles are somehow broken. This is also where a lot of misunderstandings happen so it's worth investigating the matter slightly further than what causes gimbal lock.

It is important to understand that this is *only* problematic if you `interpolate` in Euler angles\*\*! In a real physical gimbal this is given - you have no other choice. In computer graphics you have many other choices, from normalized matrix, axis angle or quaternion interpolation. Gimbal lock has a much more dramatic implication to designing control systems than it has to 3d graphics. Which is why a mechanical engineer for example will have a very different take on gimbal locking.

You don't have to give up using Euler angles to get rid of gimbal locking, just stop interpolating values in Euler angles. Of course, this means that you can now no longer drive a rotation by doing direct manipulation of one of the channels. But as long as you key the 3 angles simultaneously you have no problems and you can internally convert your interpolation target to something that has less problems.

Using Euler angles is just simply more intuitive to think in most cases. And indeed Euler never claimed it was good for interpolating but just that it can model all possible space orientations. So Euler angles are just fine for setting orientations like they were meant to do. Also incidentally Euler angles have the benefit of being able to model multi turn rotations which will not happen sanely for the other representations.

### Problems and how to circumvent them

The fact of the matter is that interpolating in Euler angle space is a bad idea, in general and affects you way before you come close to a true gimbal lock. For this reason NASA lunar orbiter would warn of gimbal lock when you come close to a 70-80 degree angle on a single gimbal's turn. So be aware that people do not necessarily talk of just the actual locking condition when they talk of a gimbal lock. Even worse some people blame all their rotation problems on gimbal locking.

Euler rotation is only safe if you rotate primarily one angle and shallow amounts on the other 2 rotations, which is quite common admittedly. This works fine for describing movement of a commercial airliner, a car etc. But not so well for a jet fighter or an acrobatics plane doing complex air maneuvers. What happens is the rotations start to interfere with each other and you get a weird wobble instead of moving straight from one position to the next.

To fix the wobble problem in shallow cases just swap the rotation order so that the big rotation gets applied on the other rotations. If you need to use more complex rotations then either switch over to other interpolation methods or add even more rotation links to your gimbal (which is a good stopgap measure for cases where you cannot do the switch in a timely manner).

---

\* To be exact most of the time people do not actually use Euler angles but Tait–Bryan angles. Which are nearly the same thing only Euler insisted on repeating the same axis, not very important distinction but good to know if you ever speak to an academic.

\*\* Oh well, if you use Euler–Lagrange equation it won't matter.

> **Comments:**
> **username_2**: finally someone saying that gimbal lock is not due to euler angles. Saying that quaternions aren't affected by gimbal lock for example is silly, since when you express a rotation sequence with them (or with rotation matrices for that matter) you get the same exact problem (because both representations are expressed in terms of euler angles). Is the ability to do spherical interpolation from one orientation to another that is correct.  

---

