How to get the "anti-clockwise" angle between two 2D vectors?

math

Solution

With the dot product you get always an angle that is independent of the order of the vectors and the smaller of the two possibilities.

For what you want, you need the argument function of complex numbers that is realized by the `atan2` function. The angle from `a=ax+i*ay` to `b=bx+i*by` is the argument of the conjugate of `a` times `b` (rotating `b` backwards by the angle of `a`, scale not considered), which in coordinates is

(ax-i*ay) * (bx+i*by) = ax*bx+ay*by + i*(ax*by-ay*bx)

so the angle is

atan2( ax*by-ay*bx, ax*bx+ay*by ).

Problem

I have two vectors and I want to get the angle between those vectors, I am currently doing it with this formula : ``` acos(dot(v1.unitVector, v2.unitVector)) ``` Here is what I get with it : I would want the green angle rather than the red angle, but I don't know what formula I should use... Thank you. EDIT : So, hen the vectors are still in a certain position (like the first two pairs of vectors, it's ok, but whenever it is in a configuration like in the third pair, it doesn't give me the right angle anymore)

Original source