
function R = rotM(v1,v2)

%%% rotate from v1 to v2 %%%
[m1,n1]=size(v1);
[m2,n2]=size(v2);
if m1 > n1
    if n1 ~= 1
        disp('Input must be vector')
        exit();
    end
    cv1=v1;
else
    if m1 ~= 1
        disp('Input must be vector')
        exit();
    end
    cv1=v1';
end
if m2 > n2
    if n2 ~= 1
        disp('Input must be vector')
        exit();
    end
    cv2=v2;
else
    if m2 ~= 1
        disp('Input must be vector')
        exit();
    end
    cv2=v2';
end
ip = cv1'*cv2;
np = norm(cv1)*norm(cv2);
if np ~= 0
    theta = acos(ip/np);
else
    disp('input must not be zero vector')
    exit();
end
axis = [cv1(2)*cv2(3)-cv1(3)*cv2(2);cv1(3)*cv2(1)-cv1(1)*cv2(3);cv1(1)*cv2(2)-cv1(2)*cv2(1)];
axis = axis ./ norm(axis);
omega = [0  -axis(3)    axis(2)
         axis(3)    0   -axis(1)
         -axis(2)   axis(1) 0];
R = eye(3) + omega .* sin(theta) + omega * omega .* (1 - cos(theta));
end



