0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ See this answer for two simple methods of extracting the rotation axis from the matrix. $\endgroup$ – amd Sep 30 '18 at 4:39
  • $\begingroup$ @amd that always fails for 180 degrees. $\endgroup$ – The Great Duck Sep 30 '18 at 4:48
  • $\begingroup$ Read the comment at the end: using the symmetric part instead of the asymmetric part works for 180 degrees, too. $\endgroup$ – amd Sep 30 '18 at 5:38
  • $\begingroup$ @amd it can't. $1-\cos(\theta)$ will be $0$.... $\endgroup$ – The Great Duck Sep 30 '18 at 5:39
  • $\begingroup$ 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. $\endgroup$ – amd Sep 30 '18 at 5:49
1
$\begingroup$

The axis of rotation has the property that

$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$.

$\endgroup$
  • $\begingroup$ By any chance do you have any suggestions for algorithms that compute that vector? $\endgroup$ – The Great Duck Sep 30 '18 at 3:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.