I have made function in Matlab, that shale calculate the rotation matrix for fi degrees around unit vector k.
function R = rot(k,fi)
rad = fi*(pi/180);
% 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) = cos(rad)+x^2*(1-cos(rad));
R(1,2) = x*y*(1-cos(rad))-z*sin(rad);
R(1,3) = x*z*(1-cos(rad))+y*sin(rad);
R(2,1) = y*x*(1-cos(rad))+z*sin(rad);
R(2,2) = cos(rad)+y^2*(1-cos(rad));
R(2,3) = y*z*(1-cos(rad))-x*sin(rad);
R(3,1) = z*x*(1-cos(rad))-y*sin(rad);
R(3,2) = z*y*(1-cos(rad))+x*sin(rad);
R(3,3) = cos(rad)+z^2*(1-cos(rad));
end
But it don't seem to work, i have a test rules
rot(k,0) == I
rot(k,fi) == rot(k,fi+360)
rot(-k,fi) == transpose(rot(k,fi))
rot(k,f1)*rot(k,f2) == rot(k,f1+f2)
rot(k,fi)*k == k
My function is always successfull on rule nr 1, 3 and sometime on 2. What am i doing wrong here? is my function not correct?