TITLE: Transformation matrix to go from one vector to another
QUESTION [9 upvotes]: I've two vectors $a = (a_1, a_2, a_3)$ and $b = (b_1, b_2, b_3)$. How to find  transformation matrix for transform from a to b?

REPLY [3 votes]: One can use axis-angle representation to get the rotation matrix.
$$Rot(u,\phi)=I \cos\phi + u u^T(1-\cos\phi) + \hat{u}\sin\phi$$
where $u$ is unit axis vector and $\phi$ is angle of rotation.
To find axis vector you need to use cross product of given two vectors $(\overline a\times\overline b)$, and from this cross product you can get first $\sin\phi$ and then $\cos\phi$.

Rodrigues' rotation formula
Hat operator