Monday, October 20

Quaternions are "complex complex" numbers, and unit magnitude quaternions are handy for representing three dimensional rotations.  And there's a variety of ways of representing them.  But opengl wants us to use x, y, z, w here "w" would be the "real" part and "x, y and z" would be the "complex parts".  this gives us compatability with x, y, and optionally z being graphical coordinates in other contexts.

Anyways, if we do it this way, and we multiply the quaternion x, y, z, w with the quaternion X, Y, Z, W, the result would be 

This is posted all over the place, and can easily be found by searching for "quaternion multiplication", but is just arbitrary enough that it does not get much support in hardware nor in many programming languages.

Also, some people like to use a slightly different expression that is equivalent to this only for unit quaternions.  But given how modern computers are architected, I am dubious of the value of that approach.

Anyways, rotations can be represented with unit magnitude quaternions, and rotations can be combined by multiplying their quaternions, arranging them in right-to-left order (the first rotation must be furthest to the right).

But you can also use quaternion multiplication with non-unit quaternions to represent the rotation of points in space.   A point in space has a w value of 0, and x, y and z are the coordinates of that point.  If we call this quaternion P and our rotation quaternion R, the rotated point position is RPr.  Here, r is the conjugate of R (in other words, using opengl's convention, -x, -y, -z, w where R would have been x, y, z, w).

So... why do we need 'r'?  My informal take on this is that we first have to rotate space around in the opposite direction from R, then we move out to our point, then we rotate space back in the R direction.  The result has our point P rotated by R.

No comments:

Post a Comment