atan2

Returns the arctangent of the quotient of its arguments.

Applies to

Math

Syntax

atan2(y, x)

Parameters

y,x

A number.

Description

The atan2 method returns a numeric value between -pi and pi representing the angle theta of an (x,y) point. This is the counterclockwise angle, measured in radians, between the positive X axis, and the point (x,y). Note that the arguments to this function pass the y-coordinate first and the x-coordinate second.

atan2 is passed separate x and y arguments, and atan is passed the ratio of those two arguments.

atan2 is a static method of Math. As a result, you always use it as Math.atan2(), rather than as a method of a Math object you create.

Example

The following function returns the angle of the polar coordinate:

function getAtan2(x,y) {
      return Math.atan2(x,y)
}

If you pass getAtan2 the values (90,15), it returns 1.4056476493802699; if you pass it the values (15,90), it returns 0.16514867741462683.

See also

Math.acos, Math.asin, Math.atan, Math.cos, Math.sin, Math.tan