Normalising angle between negative y-axis and vector

  angle, atan2, c++, math

enter image description here

From picture: I have to calculate alpha, defined as the angle between the lines that connects two points and the y-axis, with a range 0 to 180 in the direction that can be seen in the image, and with a range of 0 to -180 in the opposite (arrow pointing from current starting point to finger1).

(atan2((x1 - x), (y - y1)) * 180/ M_PI );

I managed to do so with this formula, simply inverting x and y reference in atan2 function, but this works only when the first point (x,y) is on "bottom-right" in respect of the second.
In that case I get the exact expected result. In all the others obviously I get wrong values. How could I normalise this to get always the same values?

Source: Windows Questions C++

LEAVE A COMMENT