如果已知旋转前后向量的变化,如何求旋转矩阵呢?
1、旋转角度:已经旋转前向量P及旋转后向量Q,由点积定义可知

P.Q =|P| |Q| cos(theta)

2、旋转轴:由上可知,旋转角所在平面为P和Q构成的平面,那么旋转轴必定垂直于该平面,

A X B =(a2b3-a3b2)i + (a3b1-a1b3)j + (a1b2-a2b1)k

3、根据罗德里格旋转公式求旋转矩阵

![罗德里格旋转公式](http://snailgoers.qiniudn.com/rodrigues (1).png)

4、Code

function RotateMatrix=F_GetRotateMatrix(vectsrc,vectdst)

angle=acos(dot(vectsrc,vectdst));
vector=cross(vectsrc,vectdst);


% normalization
vector=vector/norm(vector);

cost=cos(angle);sint=sin(angle);
x=vector(1);y=vector(2);z=vector(3);

%rotate matrix
RotateMatrix=[x*x*(1-cost)+cost (1-cost)*x*y-sint*z (1-cost)*x*z+sint*y;
(1-cost)*y*x+sint*z (1-cost)*y*y+cost (1-cost)*y*z-sint*x;
(1-cost)*z*x-sint*y (1-cost)*z*y+sint*x (1-cost)*z*z+cost];