JavaScript atan2() method

Definition and usage

atan2() The method can return the angle between the X-axis and the point (x,y).

atan2() The method returns the arctangent of the quotient of its parameters, returning a value between -PI and PI.

The returned number represents the counterclockwise angle (not in degrees) between the positive X-axis and the point (x,y) in radians.

Note:Note the order of the function's parameters, the Y coordinate is passed before the X coordinate.

Example - atan2(y,x)

Assuming you have a point with coordinates (x,y) of (4,8), you can calculate the angle between the point and the positive X-axis as follows:

Math.atan2(8, 4);

Try it yourself

Syntax

Math.atan2(y, x)
Parameters Description
y Required. A number. Represents the y coordinate.
x Required. A number. Represents the x coordinate.

Technical details

Return value: Numbers, from PI to -PI, or NaN if the value is empty.
JavaScript version: ECMAScript 1

Browser Support

Math.atan2() Is an ES1 feature (JavaScript 1999). All browsers fully support it:

Chrome IE Edge Firefox Safari Opera
Support Support Support Support Support Support

Related Pages

Tutorial:JavaScript Mathematics