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