Wednesday, January 20, 2010

3D Rotation: Theory (Part I)

Rotating a set of points around an arbitrary axis in three dimensions takes a few steps, and can therefore be a little intimidating to grasp the concept. The main idea, though, is that the scene can be transformed so that the arbitrary axis becomes the z-axis.  At that point, the rotation can be considered a two-dimensional rotation (with the z-component of the rotating points remaining unchanged).  It then suffices to undo the original axis-alignment transformation, to put the arbitrary axis back in its original location.

If your arbitrary axis is part of an orthogonal set (in three dimensions, that is three axis at right angles to one another), I believe you can perform a simple change-of-basis transformation.  I haven't done the math on that, though, since it's a special case of what I'm attempting generally.

The two-dimensional rotation equations can be applied in any of the three basic planes (xy, xz, yz).  Given the x, y and z components of the axis vector (which we'll call u, v and w, respectively), we can determine the angles to use in the 2D rotations.  We'll first rotate the scene around the z axis so that the axis vector lies in the xz plane.  Next, we'll rotate the scene around the y axis so that the axis vector lies along the positive z axis.

The angle of rotation around the z axis (α) is found in terms of u and v (the lengths of the components orthogonal to the z axis):


We can apply the angle (α) to the two-dimensional rotation equation.  We must be careful to note, however, that the rotation in this case is clockwise (the previously-derived equations are for a counter-clockwise rotation).  We can simply use a negative angle, noting that cos(-θ) = cos(θ) and sin(-θ) = -sin(θ):

These equations, like those for the two-dimensional rotation, can be represented in matrix form.

The next step is to rotate the resulting vector around the y axis, until it lies along the z axis.  Looking from the positive y axis, the rotation onto the z axis is another clockwise rotation.  The components we'll use to find the angle of rotation (β), are a little more complicated this time.  Along the z axis is w (simple enough), but along the x axis, the value is the length of the original vector's projection into the xy plane ().

As before, we find the angle of rotation around the axis:


Once again, we apply this angle to the two-dimensional rotation equations, noting that we're using different axes.  What was originally x is now z, and y has become x.


Applying these equations, the axis of rotation will become the new z axis.  As was stated previously, the problem can be treated at this point like a two-dimensional rotation in the xy plane.  After that, these transformations to rotate the axis vector must be undone.  Matrix math can help significantly with that, and will be explored in the next post.

No comments:

Post a Comment