Quaternions

I first stumbled upon quaternions when I was trying to solve a different problem. They are a neat way of representing rotations - in fact the VbRotation class I found on the web uses quaternions and is part of the VRML implementation.

A rotation is usually represented as a 3D vector and an angle around the vector. This can also be represented by a quaternion. The result of two rotations is another rotation. Determining the resulting rotation is easily done using quaternions. Just multiplying the two quaternions representing the two rotations gives a third quaternion representing the resulting rotation.

Quaternions are used in the DualJoint3D class to convert the XY position from the 2DOF control and the twist from the 1DOF control into a single rotation to be passed on to the VRML joint. The X and Y position values, depending on the limb, usually represent rotations around the Z and X axes respectively. The java control returns a value between -1 and +1. This is scaled to -90 to +90 degrees for the Z axis rotation and -180 to +180 degrees for the X axis rotation.

Adding the twist is a little more involved. It is the rotation about the axis of the limb after the Z and X axis rotations are applied. To determine the axis, the two rotations are applied to a vector representing the limb at rest position. The new vector gives the axis of the limb. The third rotation is the value from the 1DOF control scaled to -180 to +180 degrees around the new vector. Besides combining the three rotations, quaternions are also used for obtaining the vector representing the new axis of the limb.

The rotation of the limb around the X axis must be compensated for when the twist is applied. For example, the toes of a humanoid point straight at you. If the leg is stretched out a little(i.e. rotated around the Z axis), the toes still point straight ahead. Now if the leg is rotated around the X axis, the toes will point in a different direction. This is compensated by applying the right amount of twist to the limb so that the toes continue pointing at the viewer. In effect, the actual twist applied is the twist set by the 1DOF control minus the twist caused by the rotation around the X axis.

While quaternions don't give me a warm fuzzy feeling, problems such as these would be beyond me without their help. The quaternion is represented by the java class Qnion. It is an extension of the VbRotation class I found on the web. It has constructors that take any one of the following set of arguments.

  • Nothing
  • An axis represented by a vector and an angle of rotation around it
  • A VbRotation object
  • The four coefficients of a quaternion
It has the following methods.
  • Set the quaternion by specifying a vector and an angle of rotation
  • Multiply the current quaternion with another one and return the result
  • Normalise the quaternion to a unit quaternion. This is always called on a change in value. Therefore, the quaternion is always a unit quaternion.
  • Get the quaternion as a vector and an angle of rotation
  • Get the magnitude
  • Get the conjugate of the quaternion
  • Get the inverse of the quaternion
  • Rotate a vector by applying the rotation represented by this quaternion
 



  Quaternion Links
 

HomePreviousNextFeedback