atan2 Function

Top  Previous  Next

Returns the arctangent of the quotient of its arguments, as a numeric value between PI and -PI radians.


Math.atan2(number2, number1)


number2 A number representing the y coordinate of a point.
number1 A number representing the x coordinate of a point.        

Return Value

A number which represents the counterclockwise angle in radians between the positive X axis and the point (number1, number2). The function returns NaN when given a NaN argument.


The order of arguments is reversed; the function atan2(y, x) computes the angle corresponding to the point (x, y).


Math.atan2(0,1);          // Returns 0

Math.atan2(0,0);          // Returns 0

Math.atan2(-1000,0);       // Returns -1.570796

Math.atan2(-10000, -1000);     // Returns -1.670465

See also