Atan2 Function: angle out of the domain

Hi there,
By comparing these two results, I doubt there is a bug in Math.Atan2.
One of the results unexpectedly is out of the domain: {-180, 180},
Perhaps if the angle is not too close to -90 or 90, seemingly it will not fail :thinking:

Atan2_out of (12.8 KB)

Hi @Tanik,

In your c#:
double Ang = Math.Atan2(V2.Y, V2.X) - Math.Atan2(V1.Y, V1.X)
each part on the right side will produce an angle θ such that -π ≤ θ ≤ π. Then you subtract one from the other giving an angle θ’ such that -2π ≤ θ’ ≤ 2π.

e.g. you might subtract π from -π giving -2π.


HI @jeremy5 ,
Thank you, maybe not by your intention,
but your answer just gives me the hint that the (x, y) order matters,
which I did find the defect from my c# .
where vector at the fourth quadrant by giving (y, x), it switches the coordinate to the second quadrant.
see the attached: