Returns the angle in radians between the positive x-axis and the ray from the origin to the point (x, y). This is the two-argument arctangent, equivalent to atan(y/x) when x > 0, but correctly handles all four quadrants.
Syntax
double atan2(<y>, <x>)
Parameters
-
y: Required. The y-coordinate of the point. Accepts DOUBLE. STRING, BIGINT, and DECIMAL values are implicitly converted to DOUBLE before calculation.
-
x: Required. The x-coordinate of the point. Accepts DOUBLE. STRING, BIGINT, and DECIMAL values are implicitly converted to DOUBLE before calculation.
The first argument is the y-coordinate, not the x-coordinate. This is the opposite of the conventional (x, y) order and a common source of errors.
Return value
Returns a DOUBLE value in the range [-π, π], in radians. If either y or x is null, null is returned.
Usage notes
-
STRING, BIGINT, and DECIMAL inputs are implicitly converted to DOUBLE.
-
If either argument is null, the return value is null.
-
The return value is in radians, not degrees.
Examples
-- Returns 0.0, the angle for the origin point (x=0, y=0)
select atan2(0, 0);
-- Returns 0.7853981633974483 (π/4), the angle for the point (x=1, y=1)
select atan2(1, 1);
-- Returns 0.0, the angle for a point on the positive x-axis (x=1, y=0)
select atan2(0, 1);
Related functions
ATAN2 is a mathematical function. For more information about functions related to data computing and conversion, see Mathematical functions.