# Determine what the rotation axis is given a rotation matrix

How do I find out around which axis the coordinate system has to rotate, if the rotation matrix is given?

${^{a}R_{b} }$ = $\left(\begin{matrix} 0 & 1 & 0 \\ -1 & 0 & 0 \\ 0 & 0 & 1 \\\end{matrix}\right)$

${^{a}R_{c} }$ = $\left(\begin{matrix} 0 & 0 & 1 \\ 1 & 0 & 0 \\ 0 & 1 & 0 \\\end{matrix}\right)$

For ${^{a}R_{b} }$ I thought, that it has to be a rotation around the z-axis, because $R(z,\theta) = \left(\begin{matrix} cos(\theta) & -sin(\theta) & 0 \\ sin(\theta) & cos(\theta) & 0 \\ 0 & 0 & 1 \\\end{matrix}\right)$

the values at the positions $a_{13}, a_{23},a_{33},a_{32},a_{31}$ of ${^{a}R_{b} }$ and $R(z,\theta)$ are identical.

So I solved $cos(\theta) = 0$ =>$\theta = 90°$ => 90° rotation around z-axis.

But how do I solve it, if there is more than 1 rotation, like for ${^{a}R_{c} }$?

• See the answer to this question. Jul 23, 2015 at 4:46

Given a rotation matrix: $$\ R = \begin{bmatrix} r_{11} & r_{12} & r_{13}\\ r_{21} & r_{22} & r_{23}\\ r_{31} & r_{32} & r_{33} \end{bmatrix} \\$$

You can get the rotation angle: $$\theta = \cos^{-1} \left[ 0.5(r_{11} +r_{22} + r_{33} - 1) \right] \\ n_x = \frac{r_{32} - r_{23}}{2 \sin(\theta)} \\ n_y = \frac{r_{13} - r_{31}}{2 \sin(\theta)} \\ n_z = \frac{r_{21} - r_{12}}{2 \sin(\theta)} \\$$

So, given your first problem: $$R = \begin{bmatrix} 0 & 1 & 0\\ -1 & 0 & 0\\ 0 & 0 & 1 \end{bmatrix} \\$$

$$\theta = \cos^{-1} \left[ 0.5(0 +0 +1 - 1) \right] \\ \theta = 1.57 \mbox{rad} = 90^{\circ} \\ n_x = \frac{0 - 0}{2 \sin(90^{\circ})} \\ n_y = \frac{0 - 0}{2 \sin(90^{\circ})} \\ n_z = \frac{-1 - 1}{2 \sin(90^{\circ})} \\ n_x = 0 \\ n_y = 0 \\ n_z = -1 \\$$ So you can see here that, for your first problem, you rotate 90 degrees about the -z axis, or equivalently, you rotate -90 degrees about the +z axis.

Similarly, for your second problem: $$R = \begin{bmatrix} 0 & 0 & 1\\ 1 & 0 & 0\\ 0 & 1 & 0 \end{bmatrix} \\$$

$$\theta = \cos^{-1} \left[ 0.5(0 +0 + 0 - 1) \right] \\ \theta = 2.09\mbox{rad} = 120^{\circ} \\ n_x = \frac{1 - 0}{2 \sin(120^{\circ})} \\ n_y = \frac{1 - 0}{2 \sin(120^{\circ})} \\ n_z = \frac{1 - 0}{2 \sin(120^{\circ})} \\ n_x = 0.577 \\ n_y = 0.577 \\ n_z = 0.577 \\$$

Here you have an axis of rotation that is x=y=z=0.577 (but could be scaled to, say, x=y=z=1, just for thinking about the nature of the rotation), and then you rotate +120 degrees about that axis.

Hope this helps; please comment if I've left something unclear.

For starters, the product of rotation matrices are not unique.

Any orientation can be achieved by composing three elemental rotations.1

To recover a set of rotation angles you'll need to start with the full rotation matrix and then work backwards. Let's look at a 3-2-1 rotation.

${R_{321} }$ = $\left(\begin{matrix} cos\theta cos\phi & cos\theta sin\psi & -sin\theta \\ sin\phi sinθcosψ−cos\phi sinψ & sin\phi sinθsinψ+ cos\phi cosψ & sin\phi cosθ \\ cos\phi sinθcosψ+ sin\phi sinψ & cos\phi sinθsinψ−sin\phi cosψ & cos\phi cosθ \\ \end{matrix}\right)$

We can now solve for $\theta$. This can be used to solve for $\psi$ and $\phi$. Looking at your $^aR_c$ matrix, we can find the $\theta$ is $-\frac{\pi}{2}$, $\psi$ is $-\frac{\pi}{2}$, and $\phi$ is 0.

__

For solving individual cases, if you do not want to script yourself, you can enter the matrix in this Online Calculator for 3D Rotation Formats, switch the output to degrees, and see the axis-angle output.

In case your of ${}^aR_c$, it outputs a 120 degrees rotation around the axis [0.5773503, 0.5773503, 0.5773503].

Consider an arbitrary rotation matrix $$\bf R$$ $$\in$$ SO(3). We can use it transform a vector $$v \in {\mathbb R}^3$$ by $$w = {\bf R}v$$ Intuitively, if $$v$$ corresponds to the rotation axis of $$\bf R$$ then it will be unchanged by the rotation, that is, $$w = v$$.

So the rotation axis must be an eigenvector of $$\bf R$$. Since $$\bf R$$ is a 3x3 matrix it has 3 eigenvectors. Each eigenvector has an associated eigenvalue: there is always at least one eigenvalue equal to 1 (ie. the vector's length is unchanged by the rotation), and for non-zero rotation the other two eigenvalues are a complex conjugate pair. The eigenvector corresponding to the eigenvalue equal to one is the rotation axis.

A simple example in MATLAB

>> R = roty(0.3)
R =
0.9553         0    0.2955
0    1.0000         0
-0.2955         0    0.9553


which is a rotation of 0.3 radians about the y-axis (this function is from my Robotics Toolbox for MATLAB).

>> [x,e] = eig(R)

x =

0.7071 + 0.0000i   0.7071 + 0.0000i   0.0000 + 0.0000i
0.0000 + 0.0000i   0.0000 + 0.0000i   1.0000 + 0.0000i
0.0000 + 0.7071i   0.0000 - 0.7071i   0.0000 + 0.0000i

e =

0.9553 + 0.2955i   0.0000 + 0.0000i   0.0000 + 0.0000i
0.0000 + 0.0000i   0.9553 - 0.2955i   0.0000 + 0.0000i
0.0000 + 0.0000i   0.0000 + 0.0000i   1.0000 + 0.0000i


where x is a matrix whose columns are the eigenvectors, and e is a diagonal matrix of eigenvalues. The unit eigenvalue is in column 3 so our rotation axis is the third column of x which is real and equal to $$[0, 1, 0]^T$$ which is a unit-vector parallel to the y-axis — the original axis of rotation.

The complex eigenvalues tell you about the amount of rotation around the axis

>> angle(e(1,1))
ans =
0.3000


The Toolbox has a function which does all this for you

>> [theta,v] = tr2angvec(R)

theta =
0.3000

v =
0    1.0000         0


To go in the opposite direction, from a rotation axis and angle, to a rotation matrix use Rodrigues' formula. This is provided in the Toolbox as

>> angvec2r(theta,v)
ans =
0.9553         0    0.2955
0    1.0000         0
-0.2955         0    0.9553