MySQL ATAN2() Function
The ATAN2()
function in MySQL calculates the arctangent (inverse tangent) of two numbers, returning the angle (in radians) whose tangent is the ratio of the two input numbers. This is particularly useful when working with Cartesian coordinates.
ATAN2(): Definition and Usage
Unlike the single-argument ATAN()
function, ATAN2()
takes two arguments representing the y and x coordinates of a point. It computes the angle between the positive x-axis and the line segment from the origin (0,0) to the point (x, y). The result is an angle in radians and takes into account the signs of both input numbers to determine the correct quadrant.
Syntax
Syntax
ATAN2(a, b)
Parameter Values
Parameter | Description |
---|---|
a |
The y-coordinate (a numeric value). This is required. |
b |
The x-coordinate (a numeric value). This is required. |
Examples
Calculating the Arctangent of Two Values
This calculates the arctangent of 0.5 (0.5 / 1).
Syntax
SELECT ATAN2(0.50, 1);
Output
0.463647609000806 (Result in radians)
Calculating the Arctangent of Two Other Values
Another example with different input values.
Syntax
SELECT ATAN2(-0.8, 2);
Output
-0.38050637711219 (Result in radians)