📦 Archived documentation: r1 (committed 2026-10-07) View current documentation →

Math.atan2()

Math.atan2(y, x) → number

Returns the arctangent of the quotient of its arguments.

Returns the angle, in radians, between the positive x-axis and the point (x, y). Note the argument order: y comes first. The result is in the range -π to π, and the signs of both arguments are used to determine the quadrant.

Arguments

NameTypeRequiredDefaultDescription
y number optional — The y coordinate.
x number optional — The x coordinate.

Returns

number The angle in radians between the positive x-axis and the point (x, y).

Example

let heading = Math.atan2(1, 1); // 0.7853981633974483