Monday, April 25, 2011

Orientation representations

The orientation of objects can be represented in multiple ways: Euler angles, matrices, angle and axis, and quaternions.

Euler angles
The orientation is represented as three rotations about the basis vectors.  Rotation about the x-axis is called "pitch" (also "attitude").  Rotation about the y-axis is called "yaw" (I think this is also called "heading", but that might only be me).  Rotation about the z-axis is called "roll".  This representation requires the least amount of memory; you only need to store three angles.  It is also very easy to look at (such as in a debugger or in an object editor) and understand the orientation.  However, the order in which you apply these rotations matters so you want to make sure you pick an order and stick with it (pitch, then yaw, then roll for example).  This representation is prone to problems as well, such as gimbal lock and it is a nightmare to interpolate.

This is just a normal rotation matrix.  This representation requires the most memory (9 variables in 3D), is difficult to interpolate, and is pretty much impossible to look at and understand the orientation based solely on the variables.  However, this representation can be used directly to transform vectors and points; the other representations need to be converted to matrix form before they can be used to perform transformations.  One interesting thing I learned about these is that you can get the inverse of a rotation matrix by simply transposing it.

Angle and axis
The orientations is represented as a rotation about a certain axis.  I have the least experience with this representation, so I can't comment on it much.  It seems like this would be a half-way point between Euler angles and matrices.  I'm not sure how interpolation would work, but from what I understand this representation does not suffer from gimbal lock.  It also requires less memory than a matrix, but slightly more than Euler angles.

I have only read about these, but they seem to be a way of using the angle and axis representation in one variable rather than two.  I'm guessing that bunching the angle and axis into one "variable" makes performing math on it easier, but as I said I have no actual experience with using them yet.  This representation is the easiest to interpolate, and it doesn't suffer from the same problems that Euler angles do.  Due to the normal problems with representing fractions on a computer though, these can become invalid, and quickly; quaternions, when used to represent orientation, must have a magnitude of 1.

2D games normally use Euler angles to represent orientation, when orientation is even needed.  Some of the more advanced ones will use matrices, but angle and axis/quaternions are only really worth it in 3D because the axis is always the z axis in 2D.

No comments:

Post a Comment