How to find out if the angle between two vectors i

2019-02-27 01:03发布

问题:

I know how to find out angle between 2 vectors, but it always gives me internal angle, but I want it to give me always the angle in anticlockwise direction, even if it is greater then 180. I'm using C++ but it is not really important because I need to get the theory.

This is what I am using now

回答1:

You're looking for the atan2(y,x) function (http://en.wikipedia.org/wiki/Atan2). If you give it the two components of a 2D vector, it will give you the angle of the vector from the x axis, in the counter-clockwise direction. To solve your specific problem try:

atan2(v_y, v_x) - atan2(u_y, u_x)

Then you can add or subtract 360 degrees if the answer is out of the range of angles you desire.