Skip to content

atan2

The atan2() method returns the arctangent of the quotient of its arguments (y/x), taking into account the signs of both arguments to determine the correct quadrant. Unlike atan(), it returns an angle between -π and π, covering all quadrants of the trigonometric circle.

Interactive example

Syntax

Classic signature

typescript
function atan2<
	GenericAxisY extends number
>(
	axisY: GenericAxisY,
	axisX: number
): number

Curried signature

typescript
function atan2<
	GenericAxisY extends number
>(
	axisX: number
): (axisY: GenericAxisY) => number

Parameters

  • axisY: The y coordinate (or vertical component, classic signature only).
  • axisX: The x coordinate (or horizontal component).

Important note: The parameter order in the classic signature is axisY then axisX, which follows the standard mathematical convention atan2(y, x).

Return value

returns the angle in radians (between -π and π) between the positive x-axis and the point (axisX, axisY).

See also

  • atan - Calculates the arctangent (single quadrant)
  • tan - Calculates the tangent of an angle
  • sin - Calculates the sine of an angle
  • cos - Calculates the cosine of an angle

Sources

Released under the MIT license.