METHOD:
Math::atan2
Math.atan2(y,
x)
The atan2 method returns the arctangent of the quotient of
its two arguments. Compare this to the atan method whose single
argument is the ratio of these two coordinates. Specifically, the angle
returned is a numeric value between PI and PI and represents the counterclockwise
angle in radians (not degrees) between the positive X axis and the point
(x, y).
NOTE:
The y coordinate is passed as the first argument and the x coordinate
is passed as the second argument, i.e. atan2(y, x). This is purposeful
and is agreement with the ECMA262 standard.
Assuming you had a point with the (x, y) coordinates of (3, 6), you
could calculate the angle in radians between that point and the positive
X axis as follows:
Code:
Math.atan2(6, 3)
output:
0.4636476090008061
This is equivalent to calculating the arctangent of the ratio of these
two coordinates, which is 6/3 = 2, as follows:
Code:
Math.atan(2)
output:
0.4636476090008061
