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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
| 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