# Calculating the axis used to rotate a matrix 90 degrees

I have a problem that I can't seem to get worked out. I have two rotation matricies:

$$R_1 = \left( \begin{array}{ccc} 1 & 0 & 0 & 567.057 \\ 0 & 1 & 0 & -138.337 \\ 0 & 0 & 1 & 2207.99 \\ 0 & 0 & 0 & 1 \end{array} \right)$$

$$R_2 = \left( \begin{array}{ccc} 0.979994 & -0.199026 & 0 & 558.586 \\ 0 & 0 & -1 & 327.238 \\ 0.199026 & 0.979994 & 0 & 2676.21 \\ 0 & 0 & 0 & 1 \end{array} \right)$$

I know that $R_2$ is the result of $R_1$ being rotated $90^\circ$ around a vector/axis in space. How can I find the location and direction of that vector/axis?

Any help or direction would be very helpful. It's been too long since I've done this sort of math.

Update:

The $4\times4$ matricies are a combination of a rotation matrix and a translation matrix in 3D space. The first three columns and rows are the rotation and the last column is the position. I am looking for the axis that would make $R_1 = R_2$ if $R_1$ was rotated 90 degrees around that axis.

-
These matrices are $4\times 4$... does that mean you are doing rotations in $\Bbb R^4$? If so, then there is not a unique axis of rotation... Are they being used as rotations by multiplication or by conjugation? Direction of axis of what... R1? R2? the composite? –  rschwieb Mar 20 '13 at 18:56
Actually this setup looks very familiar as some 3-d rotation scheme... but I will need someone's help to point me to the right idea online somewhere :) –  rschwieb Mar 20 '13 at 19:31
@rschwieb, these are probably affine transformations, not linear ones, hence the matrices operate on homogenous coordinates. Just guessing, though. –  MvG Mar 20 '13 at 19:32
@MvG Thank you very much :) That's very plausible. –  rschwieb Mar 20 '13 at 19:34
Naming the basis directions $x,y,z$ in that order, the upper 3x3 block of $R_2$ makes it look like the $x-z$ plane was rotated by $\arccos(0.979994)$ radians, and then reflected through that plane. However, when I perform that operation, I get two out of four numbers wrong in the last column. –  rschwieb Mar 20 '13 at 19:57

I'll assume that you are talking about affine transformations in $\mathbb R^3$. Both the text of your question and the form of these matrices suggests as much although it doesn't really say so. In that case, the last column describes a translation, while the first three columns and the first three rows describe a rotation as well as any scaling or shearing which might be going on besides. The last row will always be of the form $(0, 0, 0, 1)$ so it doesn't contribute much information.

# Analyzing $R_2$ by itself

## Direction

The $3\times 3$ linear block of $R_1$ is the identity matrix, so there is no rotation going on there, just the translation. For $R_2$ that block is a rotation matrix. You can look at its eigenvectors to learn more: it has two complex conjugate eigenvalues corresponding to the rotation and one real eigenvalue which is $1$ up to rounding errors. The eigenvector for that eigenvalue is your axis of rotation. So in your case it is

$$v\approx\begin{pmatrix}-0.990047\\0.099518\\-0.099518\end{pmatrix}$$

which is almost your first coordinate vector. So it's a rotation approximately about the $x$ axis.

## Location

Now that you have the direction of your axis of rotation, you might ask about the location of that axis in space. One way to obtain that axis is by looking at the eigenvectors of the full matrix. A fixed point is an eigenvector for the eigenvalue 1 which has a 1 in its last coordinate (as we are dealing with homogenous coordinates). The axis of rotation consists of fixed points. Indeed there is a two-dimensional eigenspace for eigenvalue 1, so it will contain a 1-dimensional affine subspace with last coordinate 1. The numbers are pretty ugly, but if you add the two eigenvectors and scale the last coordinate to 1 you get something like

$$\frac{1}{2.58782\times10^{-10}} \left( \begin{pmatrix} 0.990047\\-0.0995183\\0.0995184\\2.58782\times10^{-10} \end{pmatrix} + \begin{pmatrix} -0.990047\\0.099518\\-0.099518\\0 \end{pmatrix} \right) \approx \begin{pmatrix} 0\\-1159\\1546\\1 \end{pmatrix}$$

So you now have both the direction and the position of the axis for $R_2$. Although the numeric precision is pretty bad, so some other answer might suggest a better way to do this. If done without rounding errors along the way (i.e. in sage using the algebraic number field $\bar{\mathbb Q}$ as the underlying field), the result will look more like

$$\begin{pmatrix}0\\-1107\\1513\end{pmatrix}$$

# Relation between $R_1$ and $R_2$

You asked about the rotation which changes $R_1$ into $R_2$. There are basically two possible interpretations of this concept of “rotating a matrix”:

\begin{align*} R_2 &= A\cdot R_1 \\ R_2 &= R_1\cdot B \\ \end{align*}

Depending on which interpretation you mean, you can solve this equation for the matrix in question, and then perform steps like I did for $R_2$ to obtain details on that matrix. In both cases the axis will have the same direction $v$ as $R_2$ has by itself. A point on each of these axes would be

\begin{align*} P_A &\approx \begin{pmatrix}0\\-83.49\\2617.9\end{pmatrix} & P_B &\approx \begin{pmatrix}0\\-2.15\\466.9\end{pmatrix} \end{align*}

-
Aha, good catch :) Logical way to rule that one out... –  rschwieb Mar 20 '13 at 20:56