In the past few weeks, my colleague Naiqi Weng had to work on an issue where someone had a Maya manipulator that contains both a rotateManip and a directionManip, which controlled one single “rotate” attribute. The manipulator was working fine excepted under some specific rotations where the directional manipulator "pops" the object's rotation. She noticed that when this was happening there was two axes on top of each other when looking at the rotateManip and the rotateMode was in "Gimbal" mode, which would mean that this was happening due to gimbal lock.

Having more than one manipulators control one single attribute is not a recommended way to work with manipulators.

Gimbal lock is the loss of one degree of freedom in a three-dimensional space that occurs when the axes of two of the three gimbals are driven into a parallel configuration, "locking" the system into rotation in a degenerate two-dimensional space. The only way to avoid gimbal lock is to use quaternion instead of euler to represent rotations.

In this specific situation, unless both rotate manip and direction manip use quaternion, the gimbal lock behavior can NOT be avoided. Quaternion can uniquely identify a rotation, but when it is converted into euler rotation, it loses one degree of freedom information. Let’s say you have rotated your object with your rotate manipulator, and you used the quaternion rotation. Now you want your direction manip to follow the rotate manipulator rotates, you convert the quaternion to euler rotation and get an angle of what the current direction manip should be, however you will never tell whether this direction manip should rotation from original direction to this angle from clock wise, or counter clock wise, because either way, you get the same end result, which is the current direction manip location.

Quaternion is a 4D representation which represents 3D rotation, that’s why it is sufficient to avoid any ambiguities, while euler is 3D representation and the gimbal lock ambiguity cannot be removed in this representation. Quaternion is a data type suitable for defining object orientation and rotations. Quaternions are easier to work with than matrices and using quaternions helps to avoid gimbal lock problem like in case of Euler angles usage.

Tasks like smooth interpolation between three-dimensional rotations and building rotation by vector are fairly simpler to solve with quaternions than with Euler angles or matrices. Industrial grade inertial trackers and many other orientation sensors can return rotational data in quaternion form, also to avoid gimbal lock problem, and make such values easier to filter by interpolation.

Unfortunately the Maya manipulator API are not exposed for quaternions yet. For now, the only workaround would be to track the rotation direction of the objects manually.

## Comments

You can follow this conversation by subscribing to the comment feed for this post.