# How to convert from a rotation matrix to a rotation about an axis, and in particular when the angle is 180?

I've been trying for the past couple of days to write an algorithm to convert a rotation matrix to a rotation about an axis. After dealing with a couple other issues I found that the problem was converting a matrix when the angle is 180 degrees or pi radians. The problem is that I'm not even certain if I can, and yet I need to do so in order to convert a transformation to a form I can use.

I know that the cosine of the angle is the sum of the components of the diagonal of the matrix plus $$1$$ and divided by $$2$$. I also know that the angle itself can be chosen as either so long as further calculations use that same angle.

For example one matrix I had was

$$\begin{bmatrix}0 & 0 & -1\\0 & -1 & 0\\-1 & 0 & 0\end{bmatrix}$$

According to the formula for the angle this matrix has a rotation angle of 180. Now of course this is just an example but I cannot mentally conceive what sort of vector the rotation will rotate around. I can imagine components of the reflection but I cannot conceive how I would get the rotation vector or how I would visualize it.

Note the assumption here is that the input matrix is a valid rotation matrix with a rotation angle of 180 degrees. Other cases have already been handled appropriately.

Edit:

The comments gave an interesting algorithm. Just take the original matrix $$M$$ and any row of the following matrix gives an axis of rotation for 180 degree rotation:

$$M + M^t + 2I = T$$

However consider the following:

$$\begin{bmatrix}-1 & 0 & 0\\0 & 0 & -1\\0 & -1 & 0\end{bmatrix}$$

The first row of $$T$$ for that matrix is all $$0$$'s, and so the algorithm fails.

• See this answer for two simple methods of extracting the rotation axis from the matrix.
– amd
Sep 30, 2018 at 4:39
• Read the comment at the end: using the symmetric part instead of the asymmetric part works for 180 degrees, too.
– amd
Sep 30, 2018 at 5:38
• And yet, astonishingly, it does. Try it: for your example $R+R^T-(\operatorname{tr}R-1)I = \small{\begin{bmatrix}2&0&-2\\0&0&0\\-2&0&2\end{bmatrix}}$. The nonzero rows of this matrix are in fact the correct rotation axis. $1-\cos\pi=2$ might have something to do with that.
– amd
Sep 30, 2018 at 5:49
– amd
Sep 30, 2018 at 5:54
• No worries. I just got red and blue backwards in another question. Wine doesn’t really help with the math, either.
– amd
Sep 30, 2018 at 6:23

$$R v = v$$
So you have to solve for the eigenvector that corresponds to the eigenvalue $$1$$.
In this case $$v=(-1,0,1)$$. This is in the xz plane. It is in the second quadrant of that plane.
For the algorithm, do this in general. Output the eigenvector with eigenvalue 1 for any given $$R$$. That gives the axis of rotation for that $$R$$.