If I have two 3d vectors then I can use the dot product to find the angle between them. Since cosine inverse returns a value between $0^\circ$ and $180^\circ$, there are two vectors that could have had the same dot product value. If I want to rotate one vector to match the other I need to know whether to rotate $-\theta$ or $\theta$. How do I find out which direction to rotate? This image explains what I mean:


  • 2
    $\begingroup$ Look at their cross product. $\endgroup$ Dec 29, 2017 at 16:54
  • 1
    $\begingroup$ "To math" is a verb?! $\endgroup$
    – Xander Henderson
    Dec 29, 2017 at 18:38
  • $\begingroup$ @LordSharktheUnknown true, their cross product will give me two different directions; one in and the other out. but how does that tell me when theta should be reversed. if i get their cross product all that gives me is another vector. $\endgroup$ Dec 29, 2017 at 19:40
  • $\begingroup$ How do you know which rotation direction is positive and which is negative in the first place? If you look at the plane of rotation from different sides, the necessary rotation direction changes. You first have to define an orientation before your question can make sense. The cross product of the vectors can help you do that. $\endgroup$
    – amd
    Dec 29, 2017 at 20:34
  • $\begingroup$ @LordSharktheUnknown Right, I see your right. if I define a vector coming out of the screen as the axis I want to rotate about then I can use the dot product of the cross product of the two vectors and that axis. the dot product being less than or greater than 0 will represent the direction of rotation. Thanks $\endgroup$ Dec 29, 2017 at 22:03

1 Answer 1



Let's say you have two vectors, $\vec{a}$ and $\vec{b}$. They are perpendicular to $\vec{n}$, $$\vec{n} = \vec{a} \times \vec{b} \tag{1}\label{NA1}$$ If we measure the rotation around the vector $\vec{n}$, the angle between the two vectors is $\varphi$, $$\cos\varphi = \frac{\vec{a} \cdot \vec{b}}{\left\lVert\vec{a}\right\rVert \, \left\lVert\vec{b}\right\rVert} \tag{2}\label{NA2}$$

In general, we can also utilize $$\sin\varphi = \pm \frac{\left\lVert \vec{a} \times \vec{b} \right\rVert}{\left\lVert\vec{a}\right\rVert\,\left\lVert\vec{b}\right\rVert} \tag{3}\label{NA3}$$ where the sign depends on the orientation (clockwise or counterclockwise) we measure the rotation (around the plane normal $\vec{n}$) from $\vec{a}$ to $\vec{b}$.

If you have a specific unit direction vector $\hat{d}$, either parallel or opposite to $\vec{n}$, $$\hat{d} = \pm \frac{\vec{n}}{\left\lVert\vec{n}\right\rVert} = \pm \frac{\vec{a}\times\vec{b}}{\left\lVert\vec{a}\times\vec{b}\right\rVert}$$ then you can calculate the angle counterclockwise around $\hat{d}$ using $\eqref{NA2}$ and $$\sin\varphi = \frac{\hat{d}\cdot(\vec{a}\times\vec{b})}{\left\lVert\vec{a}\right\rVert\,\left\lVert\vec{b}\right\rVert}$$


In this case, there is only one "side"; the 2D coordinate plane. Here, we can use the 2D analog of the vector cross product: $$\begin{array}{l} \vec{a} = ( x_a , y_a ) \\ \vec{b} = ( x_b , y_b ) \\ \vec{a} \cdot \vec{b} = x_a x_b + y_a y_b \\ \vec{a} \times \vec{b} = x_a y_b - x_b y_a \end{array}$$ and $$\begin{cases} \cos\varphi = \frac{\vec{a} \cdot \vec{b}}{\left\lVert\vec{a}\right\rVert \, \left\lVert\vec{b} \right\rVert} = \frac{ x_a x_b + y_a y_b}{\sqrt{(x_a^2 + y_a^2)(x_b^2 + y_b^2)}} \\ \sin\varphi = \frac{\vec{a} \times \vec{b}}{\left\lVert\vec{a}\right\rVert \, \left\lVert\vec{b} \right\rVert} = \frac{ x_a y_b - x_b y_a}{\sqrt{(x_a^2 + y_a^2)(x_b^2 + y_b^2)}} \end{cases} \tag{4}\label{NA4}$$


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .