Menu

SQL Server ATN2() Function (ATAN2)

SQL Server calls the two-coordinate arctangent function ATN2() (often called atan2 in other languages). It returns the angle in radians from the positive X-axis to the ray ending at point (x, y). Pass the Y coordinate first and the X coordinate second. See Microsoft’s ATN2() reference.

Syntax

ATN2(float_expression_y, float_expression_x)

The return type is float.

Calculate an angle from coordinates

This point has a negative X value and positive Y value, so its direction is in the second quadrant:

DECLARE @x float = -1;
DECLARE @y float = 1;

SELECT ATN2(@y, @x) AS angle_radians,
       DEGREES(ATN2(@y, @x)) AS angle_degrees;
angle_radians angle_degrees
2.356194490192345 135.0

For a single tangent ratio that is known to map to the ATAN() range, use ATAN(). ATN2(y, x) uses both coordinates to determine the quadrant. Use DEGREES() when the result should be displayed in degrees.