In three dimensions, a rotation is defined by a
orthogonal
matrix with positive determinant. In general, such matrices have the real
eigenvalue 1 together with two complex conjugate eigenvalues
, wherein
is the angle of rotation. In turn, there is a
real eigenvector lying along the axis of rotation and two complex
conjugate null eigenvectors defining the plane of rotation.
However, an orthogonal matrix is also the exponential of a real
antisymmetric matrix, having the same eigenvectors but with eigenvalues
, and
. Three such matrices,
Its axis and angle can be recovered by inspection from a rotation matrix.
The direction cosines of the axis are proportional to the coefficients
of the three antisymmetric matrices
,
, and
,
whereas the angle of rotation is related to the trace via
/* sphax - generate rotation from axis and angle */
void sphax(o,th,a,b,c) double o[][3], th, a, b, c; {
double ca, cb, cc, ct, tt, st, r, t;
r=sqrt(a*a+b*b+c*c);
t=(th*3.14159)/180.0;
ca=a/r; cb=b/r; cc=c/r;
ct=cos(t); st=sin(t); tt=1.0-ct;
o[0][0]= ct+tt*ca*ca;
o[0][1]= cc*st+tt*ca*cb;
o[0][2]=-cb*st+tt*ca*cc;
o[1][0]=-cc*st+tt*ca*cb;
o[1][1]= ct+tt*cb*cb;
o[1][2]= ca*st+tt*cb*cc;
o[2][0]= cb*st+tt*ca*cb;
o[2][1]=-ca*st+tt*cb*cc;
o[2][2]= ct+tt*cc*cc;
}