Glenn Murray, Colorado School of Mines
The problem of rotation about an arbitrary axis in three dimensions arises in many fields including computer graphics and molecular simulation. In this article we give an algorithm and matrices for calculating the motion. Many of the results were initially obtained with Mathematica.
An algorithm (see Figure 1):
(1) translate space so that the rotation axis passes through the origin
(2) rotate space about the
-axis so that the rotation axis lies in
the
-plane
(3) rotate space about the
-axis so that the rotation axis lies along
the
-axis
(4) perform the desired rotation by
about the
-axis
(5) apply the inverse of step (3)
(6) apply the inverse of step (2)
(7) apply the inverse of step (1)
This algorithm assumes that the axis of rotation is not parallel to
the
-axis. If it is, we may omit steps (2), (3), (5), and (6); see
the Programming Notes in Section 8. The
choice of
-axis is arbitrary, we could just as well have used the
-axis or
-axis. The final results in
Section 6 and Section 7
are independent of the choice of axis in the algorithm.
We will write our three-dimensional points in four homogeneous coordinates; i.e., (x, y, z) will be written as (x, y, z, 1). This enables us to do coordinate transformations using 4x4 matrices. Note that these 4x4 matrices are only necessary for translations, if we omitted translations from our movements we could do the motions with 3x3 rotation matrices obtained by deleting the last rows and last columns of the 4x4 matrices. In this article vectors are multiplied by matrices on the vector's left.
The product Tp.v is equivalent to the vector sum
, i.e., this transformation moves the point
to the origin.
Here are the matrices for rotation by
around the
-axis,
around the
-axis, and
around the
-axis.
The general rotation matrix depends on the order of rotations. The
first matrix rotates about
, then
, then
; the second rotates about
, then
, then
.
In this section we introduce matrices to move a rotation vector
to the
-axis. This is illustrated in
Figure 1. Note that we use the vector's components to
form expressions for the cosines and sines. We require that the
rotation vector not be parallel to the
-axis, else
and the
denominators vanish.
The matrix to rotate a vector about the
-axis to the
-plane is
The matrix to rotate the vector in the xz-plane to the
-axis is
In this section we rotate the point
about the vector
by the angle
. The matrix for
rotations about the origin is the product
:
If we multiply this times the point to be rotated,
, we
get the rotated point:
We must give the axis an orientation so that positive and negative
angles of rotation are defined. If the axis of rotation is given by
two points
and
, then the
(oriented) vector of rotation can be given by
. The matrix for rotation about
an arbitrary line is given by the product
This is the rotation operator for rotations about the line
through
parallel to
by the
angle
. In hopes of fitting the matrix onto the page we make
the substitution
.
If we multiply this times the point to be rotated,
, we
get the rotated point.
We can extract the first terms of the homogeneous coordinates of
the rotated point in the last section to obtain a three dimensional
function of ten variables for the rotation of the point
about the line through
parallel to
by the angle
. It is simplified here as a convenience.
The most immediate way to program the result is to use the function in the last section. This is the simplest way to obtain a single rotation. However, to apply rotations to many points it is more efficient to calculate the matrix of rotation and apply it to each point.
If it is known that the axis of rotation is nearly parallel to one of
the coordinate axes then the rotation and translations matrices given
earlier can be used directly. For example, in the case of the axis of
rotation being nearlly parallel to the
-axis (say
for some small
) then the rotation can be
approximated by
, or, in the case where the
axis is oriented opposite to the
-axis, by
. This method is often given in textbooks
and online resources as it provides a check against a division by
zero error.
A Java implementation of the rotations about an arbitrary line is available at
http://www.mines.edu/~gmurray/ArbitraryAxisRotation/java.zip
Note that with most browsers, the original LATEX for the matrices may be seen by viewing the page source. This may be helpful for translation to other languages.
This document was generated using the
LaTeX2HTML translator Version 2002-2-1 (1.71)
The command line arguments were:
latex2html -white -split +0 -no_navigation ArbitraryAxisRotation.tex