Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have to write an algorithm that can given a rotation matrix, find $k$ and $f_i$. $R = \text{rotationMatrix}(k, f_i)$

I am given $R$ and need to find $k$ and $f_i$, but i don't know how to do this, and the only formula i know for converting $k$ and $f_i$ into a rotation matrix is

Rotation Matrix

Any ideas on how I can attack this problem? Maybe use another formula to figure it out from?

Edit: Thank you for the help. This is the correct function

Reverse rotation

function [ k, fi ] = arot( R )

fi = acosd(0.5*(R(1,1)+R(2,2)+R(3,3)-1));

k = zeros(3,1);
k(1) = (R(3,2)-R(2,3))/(2*sind(fi));
k(2) = (R(1,3)-R(3,1))/(2*sind(fi));
k(3) = (R(2,1)-R(1,2))/(2*sind(fi));


The rotation matrix

function R = rot(k,fi)
    % This is just to make it easyer to read!
    x = k(1);
    y = k(2);
    z = k(3);

    % Create a 3x3 zero matrix
    R = zeros(3,3);
    % We use the formual for rotationg matrix about a unit vector k

    R(1,1) = cosd(fi)+x^2*(1-cosd(fi));
    R(1,2) = x*y*(1-cosd(fi))-z*sind(fi);
    R(1,3) = x*z*(1-cosd(fi))+y*sind(fi);

    R(2,1) = y*x*(1-cosd(fi))+z*sind(fi);
    R(2,2) = cosd(fi)+y^2*(1-cosd(fi));
    R(2,3) = y*z*(1-cosd(fi))-x*sind(fi);

    R(3,1) = z.*x.*(1-cosd(fi))-y.*sind(fi);
    R(3,2) = z.*y.*(1-cosd(fi))+x.*sind(fi);
    R(3,3) = cosd(fi)+z^2.*(1-cosd(fi));
share|cite|improve this question
What are "k" and "fi" here?? Are you trying to convert a rotation matrix to axis-angle representation? – Rahul Oct 29 '12 at 9:24
This seems to be what i am looking for, but i just can't get it to work correctly, see my question for more info! – DoomStone Oct 30 '12 at 7:38
The problem is that your $k = (1,3,4)$ is not a unit vector, so the $R$ you get is not a rotation matrix. If you want to allow an arbitrary vector to be used as input, you should normalize it in the Rot function with k = k/norm(k) before doing anything with it. – Rahul Oct 30 '12 at 8:10
Rahul Narain That was the problem, plus i should use cosd instead of cos, can you write something as an anwser so you can get the bounty? :D – DoomStone Oct 30 '12 at 21:09

The trace of the matrix will give a quantity related to the cosine of the angle of rotation. It should have one eigenvector with a real eigenvalue - that will be the axis of rotation (up to a sign).

share|cite|improve this answer
I don't think i understand! If i have a k= [1,3,4] and fi = 30, will R be [[1,6.49,-0.43],[-1.41, 7.67, 11,14],[6.35,9.16,13.69]] where the trace of R will be 22.45 and the eigenvector will be [[0.71, 0.71, 0.17],[-0.09+0.55i, -0.09-0.55i, 0.60],[-0.11-0.42i, -0.11+0.42i, 0.78]] But how dose this help me? – DoomStone Oct 22 '12 at 7:42
@Doom: I don't know what you're referring to as "fi", but that matrix is far from being a rotation matrix. The fact that its trace isn't between $-1$ and $3$ is just one indication of this. – joriki Oct 29 '12 at 8:46
k is the unit vector the rotation is around, and fi is the rotation in degrees – DoomStone Oct 30 '12 at 7:28

Your function arot is fine; it's just that you're applying it to something that is not a rotation matrix in the first place, so you can't expect to get sensible results.

The method you're using in rot to create the matrix expects the input to be a unit vector and an angle. But $k=(1,3,4)$ is not a unit vector, so the $R$ you get is not a rotation matrix. If you want to allow an arbitrary vector to be used as input, you should normalize it via k = k/norm(k) before doing anything else with it.

share|cite|improve this answer

Trick in 3D space only:

Find the eigenvalues and vectors of your rotation matrix $\mathcal{R}$ $$ \mathcal{R}=P \Lambda P^{T} $$ You will find that the eigenvalues are: $ \lambda_{1}=1$, $ \lambda_{2}=e^{i \alpha}$, and $\lambda_{3}=e^{-i \alpha}$ where $\alpha$ is the angle of rotation and the eigenvector that corresponds to the eigenvalue $\lambda_{1}=1$ is the axis of rotation $\vec{e}_1=<u_x,u_y,u_z>$

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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