29
$\begingroup$

I have read the Wikipedia page on gimbal lock, and am still confused about the entire matter. My understanding is that, using a local coordinate system, if you rotate a model about its X axis then its Y and Z axes experience gimbal lock, and become "locked" together. However, my understanding is that if you rotate the X axis, then both the Y and Z axes rotate with it, and as such remain separate. Wikipedia, as always, while a good resource is difficult to understand on this topic. Could someone please endeavor to explain this to a person who does not have a Master's in physics or mathematics?

$\endgroup$

3 Answers 3

16
$\begingroup$

I gather that it's an inherent weakness of just storing three axial rotations (Quaternion, on the other hand, also evaluates orientation value).

(Per ideasman42's comment): We can easily see this for any object using Euler rotational system, by manipulating the rotation widget with transformation orientation set to Gimbal. It turns out to be easy to reproduce, by manipulating 2nd axis in the evaluation order (Z for XZY, or X for ZXY, etc.). I get the following condition on XYZ order by just manipulating Y axis:

Gimbal lock on Euler with XYZ evaluation order, by manipulating Y axis.

Here's an article and a video for alternative explanations of the condition.

$\endgroup$
7
  • 2
    $\begingroup$ Suggest trying the Gimble manipulator Orientation Mode and enable Rotate, then you can see the problem that happens when 2 axis line up. $\endgroup$
    – ideasman42
    Commented May 30, 2013 at 12:43
  • 2
    $\begingroup$ @ideasman42: That's a good demonstration tool. I think what's not readily apparent is why those axis can line up. One tends to picture Euler rotational axis as one rigid body with three perpendicular lines, rotating in unison, while the implementation is not that simple. $\endgroup$
    – Adhi
    Commented May 30, 2013 at 13:05
  • 2
    $\begingroup$ Gimbal lock does not arise because the axes are calculated sequentially. It has been proven that any rotation representation with three numbers will have a lock or singularity somewhere. You seem to imply that in the 3rd sentence too but it contradicts the 2nd? $\endgroup$
    – brecht
    Commented May 31, 2013 at 10:41
  • 1
    $\begingroup$ I don't have a good simple explanation, and it's not really wrong to state that gimbal lock specifically happens because the axes are evaluated sequentially. The way it is contrasted with evaluating the axes all at once just seems a bit misleading, doing that would come with its own unintuitiveness and locks. Rotations are just inherently difficult. $\endgroup$
    – brecht
    Commented May 31, 2013 at 12:02
  • 1
    $\begingroup$ I'll just erase the problematic sentence, then. Thanks, Brecht :) $\endgroup$
    – Adhi
    Commented May 31, 2013 at 12:09
7
$\begingroup$

First, I recommend looking at the Guerilla CG video that explains The Rotation Problem as it relates to 3d animation. This is important because it explains why Euler and Quaternion rotations are different. Unfortunately the only available copy has very poor A/V sync.

Cut to the chase in Part 2: Euler (gimbal lock) Explained

4:18—All together there are 6 parenting combinations to choose from. In each case gimbal lock occurs on the parent when the middle axis is rotated too far. 6 combinations of axes parenting, all in a state of gimbal lock: XYZ, ZXY, YXZ, XZY, ZYX, and YZX

$\endgroup$
2
  • 2
    $\begingroup$ excellent video, highly recommend others check it out, though the web.archive link is broken. $\endgroup$
    – ideasman42
    Commented May 31, 2013 at 13:24
  • 1
    $\begingroup$ Still works for me. Anyway, I just realized that the first answer already linked a YouTube version which actually does have synced audio. So my answer is kind of useless. $\endgroup$ Commented Jul 10, 2013 at 14:40
1
$\begingroup$

I'm a half-reformed pedant. I want to use terms precisely and unambiguously. And it seems that the only "right" meaning for a term is how it's used, in the context in which it is used. But the way that "gimbal lock" is used in 3D often just translates to "everything about Eulers that I don't like." Even among experienced artists. I've even heard people blame gimbal lock for issues they've had with quaternion rotations!

Part of the problem is the metaphor used to describe this "trouble with Eulers." A gimbal is a physical thing. Engineers build them. They respond to forces. At certain orientations, they get locked and stop responding to components of those forces. Before they reach those orientations (or after, if they could ever get there), they work fine. Few people have ever even touched one.

In 3D, our commands aren't forces. Bones and objects do what we tell them to do-- exactly what we tell them to do, whether we meant to or not, like petulant children. They never get locked and stop responding. The trouble with Eulers isn't limited to some particular orientation like it is with gimbals.

So I think if more people want to understand gimbal lock, ie the trouble with Eulers, it's worth it to take a step away from that particular "gimbal lock" metaphor and embrace a new one. I'll talk about the same things people mean by gimbal lock, but I'll talk about them differently-- hopefully, in a way that makes more intuitive sense.

A different metaphor than gimbal lock

Let's imagine we're in an airplane. Most of us have been. Earth is a sphere; as we fly over its surface, we're rotating about its center in three dimensions. We want to get from one place to another. How do we get there?

Problem #1: Torque.

Let's say we're in Nigeria, and we want to get to Nepal. We break out an equirectangular map of the world, plot a straight line between them, and then we fly that path. But we find that we keep turning to our left during the flight. And at the end, we've used more fuel that we ought to have:

enter image description here

It's a straight line on our equirectangular map, which divides latitude and longitude into equally sized sections. This is just like Euler rotation about the Earth, which interpolates by dividing rotation in orthogonal axes into equally sized sections. We have a starting latitude and longitude; we have an ending latitude and longitude; we interpolate linearly between them. But because our equirectangular map is a distorted map of the Earth, a straight line on that map is not the same thing as a great circle about the center of the Earth. We're not following the great circle I'm showing as a halo around the Earth. We have torque.

The reason for this torque is that all of the latitude lines on our equirectangular map are the same length. But on the sphere, in reality, the latitude lines get shorter as we move away from the equator. If we interpolate latitude at the same rate that we interpolate longitude, we'll have torque. If we wanted to avoid torque, we'd have to adjust how we interpolated latitude, on the basis of longitude, or vice versa; we'd have to do so continuously, in order to get an exact great circle.

We don't have to be rotating about the Earth for this to happen. All 3D rotations describe paths along spheres. And no spheres can be mapped onto flat planes like this, not free of distortion. So all Euler rotations have this kind of torque. Euler rotational triplets work fine, right up until we interpolate them. When we interpolate them, we find that they're giving us rotations that are distorted in the exact same way that an equirectangular projection is a distortion of the surface of a sphere.

Importantly, notice that we haven't even rotated 90 degrees! Our starting position is pretty damn close to the rest pose of these bones. (My bones' rest positions are in world axes, and we're looking down the -Y axis. We're starting from Nigeria for convenience's sake, based on the Wikipedia image I downloaded to build this.) When we use Euler angles, we see torque with any rotation that exists in more than one axis. But, we'll see more torque as we get closer to the North Pole:

enter image description here

The lines of latitude don't change size at a constant rate. They get smaller, faster as we reach the poles-- the distortion on our 2D map increases as we travel further from the equator. So even though there's no special angle that this happens at, it's fine at the equator-- at a single axis of rotation!-- but it's really bad as we approach rotations of 90 degrees.

And this is why we want to use quaternions in certain situations. They don't create any such torque. Let's look at the same rotation, interpolated via quaternion, mostly because it will prepare us for the next trouble with Eulers:

enter image description here

Unlike the Euler plane, the plane that is navigating by quaternions describes a great circle. Its path isn't straight on our equirectangular map, but it follows the great circle on the globe. Our Euler navigator will see the quaternion navigator going a completely different direction, but arriving earlier, with more fuel. They'll look at their equirectangular map, dumbfounded how a curved path could be shorter than a straight path.

Problem #2: Aliasing.

"Aliasing" here doesn't mean jagged lines, just like "rendering artifacts" doesn't mean that you're suddenly getting the Hand of Vecna in your image sequence. Aliasing means that something goes by different names. Just like Jay Z is Shawn Carter and also HOV. It's just three different names for the same person.

Euler angles are the same way. Some rotation might go by different Euler "names". That is, there are different combinations of Eulers that can describe the exact same rotation. Like, this XYZ 180,0,0 misshapen monkey is in the exact same rotation as this XYZ 0,180,180 misshapen monkey:

enter image description here

One rotation, two different Euler aliases for it. And the axes of rotation seem to have blended together.

One fairly obvious place this happens is at the North Pole. On our globe, it's a point; on our flat map, it's a line. But this happens elsewhere as well. Let's look at how that might play out in our airplane, on the map of the world, by taking a longer trip:

enter image description here

Now, we're flying all the way to Alaska. And you'll see that I used a second map of the world to describe our trip.

Think about latitude and longitude. Longitude goes all the way from -180 degrees to 180 degrees. But latitude only goes from -90 degrees to 90 degrees. After 90 degrees of rotation, it's like latitude and longitude become redundant, like they blur into each other. We could talk about being at lat/long 80,0. But we could just as easily describe that lat/long as 100, 180. And at the actual North Pole, we're at latitude 90, longitude anything! That's aliasing. We fix that, when talking about locations in the world, by limiting ourselves to latitudes in the -90,90 range, but in 3D, in Blender, we have a full 360 degrees of rotation for every axis; and for whatever reason, Blender doesn't simplify these aliases the same way we simplify the aliases of our latitude and longitude. And when we think about it, we're sending Eulers of any value: maybe -180,180, but maybe 720 degrees, or maybe 10,000 degrees. We could think of our map instead as an infinite, tiling plane of maps.

And look at what's happened to our two plane paths on the projection. Our Euler path is still a straight line, even though appears to cross the pole. But now our quaternion appears disconnected on our equirectangular map! Even though it's still a straight line, a great circle, on the sphere.

But if we look closely at that disconnect, we see that the two places are, in actuality, the exact same place. While it's flying over Greenland, it jumps from one map onto the other map, in the exact same location over Greenland. There are two different names we can call it, even disregarding Euler order. One instant, our driver reveals its YXZ rotation to be Y-32 X102 Z131. The next, Y141 X76 Z-42. These are very nearly the same rotations, just different by one single frame of travel.

Note what happens to the Euler plane. It flies onto a new tile, cross the North Pole. Why doesn't it fly straight on a single tile? Because of Blender's "anti-aliasing" which doesn't actually remove aliasing at all, it just picks an alias on the basis of a bit more context. Here, it decided it was better to fly onto a new tile than to explore the "canonical Euler" map that I already had. And note: even with a single order (these are all YXZ Eulers), there is more than one way to get from here to there.

If all you ever do to animate anything is enter numbers in XYZ rotation fields, you don't ever need to worry about aliasing. There may be multiple Euler triplets for a given orientation, but there are never multiple orientations for a given Euler triplet. And if you never rotate anything very far, then you don't have to worry about aliasing: just like on our map of the Earth, it only shows up when the rotations become large. (But, not at some particular number, not in Blender.)

But if you ever work with drivers or constraints, then you do have to worry about aliasing, because these typically work on orientations, not on raw Euler values. And so you see problems when you, say, copy rotation in only one or two axes, or without full influence, on a bone that's rotating far from rest. After a certain point, that rotation suddenly changes, just like our quaternion navigator's path seemed to suddenly change on our equirectangular map. And that will create sudden discontinuities in animation.

This doesn't mean Euler angles are bad.

There are times that you just can't get away with Euler angles, where any kind of torque is simply unacceptable, or where angles are unpredictable enough that aliasing can cause a problem. You can't use Euler angles on a Rubik's Cube. It's just not going to work.

But the greatest weakness of Euler angles is also their greatest strength. While a perfect ball joint might move in great circles, a human shoulder, under the combined forces of gravity, inertia, and several different muscles, does not. Often, we want torque, and the nature of Euler angles lets us tune that torque, by manipulating f-curve handles, in a way that quaternions do not easily allow.

More, the alternatives to Eulers have their own issues. Axis-angle rotation is nice for single axis rotation, or for rotation only from rest, but has huge torque when interpolating between two different rotated states. Quaternion rotation is unintuitive, and with Blender's implementation, leads to very uneven velocity. Plus, I don't want to give the impression that quaternions always move in great circles about their centers: the quaternions I made do, because their Y rotation is aligned with their direction of rotation (the plane points to its destination at departure, away from its departure at destination.)

So even though Eulers have these problems, you can't get away with just ignoring Euler angles. You just have to be prepared for those problems, prepared to make decisions about transformation modes, on the basis of how you're going to want to rotate.

Okay, but is this actually gimbal lock?

Like I said, sometimes when people talk about gimbal lock, they're talking about aliasing. Sometimes, they're talking about torque. Sometimes, they're talking about either. (And sometimes, they're just using a big word as a god of the gaps, to "explain" anything that they don't understand about 3D rotations.)

Now, I don't want to pretend I'm an educated mathematician. I'm not. Even if I was, that doesn't mean anything; educated mathematicians disagree with each other sometimes, or say things that are untrue. You should be skeptical. The ultimate test of what I'm saying is just whether it works for you or not.

What does Wikipedia say? If you've followed along, this paragraph that didn't make any sense before, might actually make sense now:

In formal language, gimbal lock occurs because the map from Euler angles to rotations (topologically, from the 3-torus T3 to the real projective space RP3, which is the same as the space of rotations for three-dimensional rigid bodies, formally named SO(3)) is not a local homeomorphism at every point, and thus at some points the rank (degrees of freedom) must drop below 3, at which point gimbal lock occurs.

Torque and aliasing are the same problem, seen from two different perspectives. The problem is one of mapping between these two distorted spaces. Torque is what you get with Euler bones, where you map from the flat map to the sphere. Aliasing is what you get with constraints or with physical gimbals, mapping the other way.

Are these two spaces that I've shown, a globe and a flat map, the spaces that Wikipedia is talking about? Almost. They are slices of that space. Because I have been ignoring "heading", ie Y axis rotation, we've just been looking at a subset of the problem. But what is true of one slice, here, is true of every slice. By slicing that space, I think we can understand the problem more intuitively.

It's a lot like when people try to demonstrate relativity with a rubber mat, distorted by mass. They're showing a 2D slice of spacetime, warped by mass, to demonstrate that there is no gravity-- that orbits aren't circles, but straight lines through spacetime. And, widely denigrated as it is, that's a great demonstration of relativity, that accurately represents the spaces involved; just as with Eulers, what is true of the slice, is true of all the slices.

Could I show these spaces unsliced? In one case, I could. On the flat map, we could consider heading as altitude, and then we'd have a box. And if we tiled that box infinitely, into a full, infinite, 3D space, we'd have the space of all Eulers.

But in the case of the space of all rotations, I can't. I can maybe suggest what it would look like, if we imagine a hollow sphere, where altitude inside that sphere represents heading. But, the inside and the outside of that sphere are continuous and adjacent, not distant. And, the distance between XZ rotations doesn't get bigger as we change heading, even though it's a sphere. So any actual picture I showed you of that space would be a mapping, almost as distorted as the Euler mapping, as the equirectangular map of the Earth.

And that shouldn't really be surprising, when we consider what we already know: to represent straight lines in the space of rotations, we need 4-dimensional vectors-- aka, quaternions.

Screw the math. What does gimbal lock mean for me, as a 3D animator?

If you use Eulers to represent your rotations, and you rotate in more than one axis, your rotations will be curved. They will be more curved when your 2nd or 3rd axis gets close to +-90 degrees rotation and less curved when you get close to 0 degrees. But they will be curved, at any non-zero values.

If you use constraints that turn rotations into Eulers, or transform channel drivers, you will experience discontinuities in the output. These discontinuities are hard to predict, but will not occur before 90 degrees of rotation.

If you want to use Eulers, choose your primary axis wisely and avoid large rotations.

Do not think that you can split an Euler into halves, or double it, or reasonably split it into components, or anything else. Because these are curved rotations, half of your Euler components are a rotation in a different axis than all of your Euler components, and so on.

You can represent any particular rotation using an Euler triplet, of any order. There are no rotations that can't be represented. The opposite is not true: you cannot represent any particular Euler triplet from a rotation.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .