ATAN2

Return the angle, in radians, from the origin to a point, taking the x and y coordinates separately so the quadrant is correct.

Syntax

ATAN2(x_num, y_num)
Argument Required Description
x_num Required The x coordinate (horizontal).
y_num Required The y coordinate (vertical).

Examples

Every example below was executed against VisiGrid engine 0.51.0 — not transcribed from another vendor's documentation. Reproduce any of them with vgrid calc.

Formula Result Notes
=DEGREES(ATAN2(1,1)) 45
=DEGREES(ATAN2(-1,-1)) -135 Down and to the left. ATAN of the ratio would say 45.
=DEGREES(ATAN2(-1,0)) 180 Straight left.
=DEGREES(ATAN2(0,1)) 90 Straight up — a run of zero, which ATAN cannot express as a ratio.
=ATAN2(0,0) #DIV/0! The origin has no direction.

x first, then y

Spreadsheets put the arguments in the opposite order from most programming languages. In Python, JavaScript, C and Rust it is atan2(y, x); here, as in Excel, it is ATAN2(x, y). Swapping them does not error — it gives the angle measured from the other axis, which is plausible enough to go unnoticed.

The range is -180 to 180

ATAN2 returns between -π and π — -180 to 180 degrees — measured anticlockwise from the positive x axis. For a compass-style 0 to 360, add a full turn to the negative results:

=IF(ATAN2(-1,-1)<0,DEGREES(ATAN2(-1,-1))+360,DEGREES(ATAN2(-1,-1)))  → 225

Excel compatibility

Matches Excel, including the x-then-y argument order and #DIV/0! at the origin.

Related functions

Last updated