I need to rotate 3D coordinate system so Z axis points in new direction.
So, I have a direction defined by spherical coordinates ($\theta$, $\phi$), where $\theta$ (in $[0, \pi]$ range) is polar and $\phi$ (in $[0, 2\pi]$ range) is azimuthal angles. I want to transform my 3D Cartesian coordinates so that Z is now pointing in that direction.
Now, I understand that this is not a unique transformation -- I do not care how X and Y axis are going to rotate. I am interested only in having Z axis in the right place.
Is it possible to get a transformation matrix for this?
The rotation vector can be found be taking the cross product of the original $z$-axis direction with that of the desired direction, while the rotation angle can be found using the dot product. With these two values, you can obtain the required transformation matrix (using this).