Rotate a vector to become z axis?

1.2k Views Asked by At

Say I have some vector v from the origin. I want to find the rotations required to transform v into the z-axis.

My understanding is that just 1 rotation is required, but it should be around the normal of the plane that goes through both vectors (v and the z-axis).

I can find the normal n by finding the cross product of v and the z-axis

normal = np.cross(v, (0.,0.,1.))

How can I find what angle to rotate by?

2

There are 2 best solutions below

0
On BEST ANSWER

The angle to rotate is the angle between $v$ and the $z$ axis. To obtain it, remember that

$||\vec{a}×\vec{b}||=||\vec{a}||\sin(\alpha)||\vec{b}||$

$\vec{a}\cdot \vec{b}=||\vec{a}||\cos(\alpha)||\vec{b}||$

Where $\alpha$ is the angle between the two vectors

Use this property with $v$ and the vector $(0,01)$ and you will get your result

0
On

The angle $\theta$ to rotate by is the angle between $v$ and the $z$ axis. The angle between two vectors is most easily found by utilizing the dot product: $$ v\cdot(0,0,1)=|v|\cos\theta $$