[Math] extract rotation axis and angle from d-dimensional rotation matrix

linear algebralinear-transformationsmatricesrotations

I have a rotation matrix $R$ of size ($d\times d$) – meaning, this is an orthogonal matrix with $det(R)=1$.

I want to calculate the axis of rotation for this matrix and the angle of rotation around this axis.

It is known that the axis of rotation is a $(d-2)$ dimensional hyperplane that passes through the origin. Which means that the axis hyperplane is represented by (d-2) unit vectors (the point is already known which is the origin).

Anyone knows how to find both the axis and the angle of rotation. I searched the internet and didn't find anything (except for the specific case of d=3).

Thanks.

Best Answer

First of all, you'd have to make sure that the matrix actually is a rotation. When all eigenvalues have $|\lambda_k| = 1$, the matrix won't shear or distort. Then, $|\det A|=1$, too. If $\det A=1$, the matrix keeps handiness (that is, won't mirror), too. Then you could call the matrix a rotation. You'd still have the problem that there'd not need to be a single "axis of rotation".

If you do an eigenvalue decomposition, rotations in the ordinary sense (mapping real vectors to real vectors) will show up as eigenvalues $\lambda_k=1$ (mirror-rotations as $\lambda_k=-1$), associated to a real eigenvector of length $1$ that shows the rotation axis.

In the three-dimensional case, plainly speaking, there's always exactly one of these. The other two degrees of freedom will have complex eigenvalues and complex coordinates.

If there are more of three dimensions, we could still have rotation about an axis with a specific angle. However, this is a special case. You could as well have more than one axis. Still, I'd recommend the following path, if you "just" want to solve the problem computationally:

  • Do an eigenvalue decomposition
  • Make sure that $\hspace{5px}\forall k \hspace{10px} |\lambda_k| \approx 1$. It not, fail with message "not a rotation" or deal with it some other way.
  • Find the eigenvalues $\lambda_k = 1$ - specifically not $|\lambda_k| = 1$.
  • The associated eigenvectors give the rotation axes.
  • If $\lambda_k = -1$ actually, the image is flipped (mirrored) in the direction of this axis

Additional reading:

https://en.wikipedia.org/wiki/Rotation_matrix https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation