Feedback

What's your question?

By: [ Editor ] Asked

Gimbal Lock - how to avoid it?

share your tricks how you avoid Gimbal lock in Euler rotations, and keep full degree of freedom... Parenting, constraining, quaternions..., you name it!

Add comment viewed 1,627 times Latest activity 11 months ago

or Cancel

4 answers

  • 3

julian [ Admin ]

If you are writing tools, there are a number of ways to represent orientations that are better than Euler Angles.

  • Rotation matrix
  • Aim and Up
  • Quaternions
  • Axis-Angle
  • more maybe ...

Its useful to gather techniques to convert between all the above and Euler Angles. I find, the most common reasons to manipulate orientations is to simulate the physics of rotating rigid bodies, or to create angular springs.

Try to avoid Euler rotations for this kind of stuff. They can be really annoying, not just because of gimbal lock. Say you want to make an object tumble through space constantly. If you set some keys to make linear animation curves on rx,ry, and rz you will probably not get a smooth linear tumbling motion. It will appear to change direction of rotation and look unnatural. People often try to simulate tumbling objects as particle instances like this and and find it looks weird. I think the main reason 3d apps use Euler rotations is to make manipulators easy to implement. ;)

Rotation matrices are a bit difficult to work with, and generally you don't want to expose them in a UI. They are very useful in conjunction with other transformations though, and also to help convert between other rotation representations.

Aim-Up is effectively an aim constraint. you define where you want one axis of the object to point (X for example), and an up direction (Y for example). The up is orthogonalized and then a cross product calculated to become (Z). Now you have a complete coordinate system and can construct a rotation matrix from the three direction vectors.

Quaternions are not so easy to grasp (not for me anyway). However, they are well suited to simulating angular physics because they easily represent angular momentum and torques. Most quaternion classes have linear and quadratic interpolations, meaning you can find a rotation between 2 other rotations, or on the smooth path defined by three rotations.

Axis-Angle representations I find are the easiest to work with. They are similar to quaternions, only without the imaginary stuff. Euler proved that any orientation can be represented by a rotation about one axis. So (x, y, z, theta) are all thats needed to represent the rotation. You can in fact make the axis to be the length theta, and in that way store the rotation in 3 floats. In the case that the angle is zero, the axis is zero length, but because there is no rotation you don't need the axis anyway. Say you want to create tumbling objects as in the earlier example. The change in orientation (angular velocity) is represented by a vector (R). You just keep adding R*dT every frame (dt is the time-step). You can do much more than this - add torques(springs, drag, spin impulses), all with the same representation. It makes simulating rotations nearly as easy as simulating particle positions. Once you have a final orientation you'll probably need to convert back to Euler angles for the UI.

I'll add some techniques I have found for applying torques and for various conversions in a later edit.

or Cancel
  • 1

manny [ Editor ]

From an animator's pov, I wrote a script that fixed the gimbal issues after the fact. But now, Maya has an Euler Filter in the graph editor to do that for you.

or Cancel
  • 1

hixster [ Editor ]

If you're rigging in maya, one of the most important and overlooked settings, is the transforms rotation order.

It's very important to set the rotation order to match the dominant axis of the joint in question, because this determines how the rotation are applied.

or Cancel
  • 0

xing

So far, the best way I've found for getting rid of Gimbal-Lock is to set up a driven key for a slave rotational bone/joint just under the real wrist you use. In one sentence, that sounds complex, but it's not. You place a second wrist joint just after your real wrist. You place it close, but just a little bit toward the palm, about 1/3 the distance you would place 2 joints in the pinky. that close. Not on top of each other, and not too far apart. If you think about it like a dog front leg, it will make more sense. The first joint (closer to the elbow) will handle almost all the twisting rotation (rotation along the length of the arm). The other rotations will be split between the two joints. Whenever you rotate the main joint, the Slave-Joint should get about 50% (or more) of the rotations. This joint is not part of the IK chain. It's part of the hand. By spreading the rotations over 2 joints, you cut down on the number one problem: the fact that most animators rotate the hands 90% at the start of every shot. And by removing the rotation along the arm, you remove one element of the gimbal lock: When one channel gets close to 90^ the other 2 channels freak out. You also still get to use the manipulator, because you didn't lock off any channels. Your wrists will also look a lot more realistic because your REAL Wrists have 2 rotation points (before, and after, the carpals).

or Cancel