2
$\begingroup$

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));

end

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));
end
  • 0
    What are "k" and "fi" here?? Are you trying to [convert a rotation matrix to axis-angle representation](http://en.wikipedia.org/wiki/Rotation_formalisms_in_three_dimensions#Rotation_matrix_.E2.86.94_Euler_axis.2Fangle)?2012-10-29
  • 0
    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!2012-10-30
  • 1
    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.2012-10-30
  • 0
    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? :D2012-10-30

3 Answers 3

3

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

  • 0
    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?2012-10-22
  • 2
    @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.2012-10-29
  • 0
    k is the unit vector the rotation is around, and fi is the rotation in degrees2012-10-30
3

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.

0

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