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