MySQL - ATAN2() Function
The ATAN2() function of MySQL converts rectangular coordinates (x, y) to polar (r, theta) coordinates. This method computes the phase theta by computing an arc tangent of y/x in the range of -pi to pi.
A polar coordinate system is a two-dimensional coordinate system in which each point is calculated with the help of the distance and angle from a reference point.
An arc tangent trigonometric function is defined as the inverse of the tangent on any coordinate axes. Hence, the domain of tangent function becomes the range of arc tangent function and vice-versa.
This function accepts two integer numbers as arguments and returns the arc tangent value. The quadrant of the result depends on the signs of the arguments.
Syntax
Following is the syntax of MySQL ATAN2() function −
ATAN2(Y,X)
Parameters
This function accepts two numeric values representing coordinates as a parameter.
Return Value
This function returns the angle in radians of the given values.
Example
In the following example, we are using the MySQL ATAN() function to calculate the arctangent of two numbers −
SELECT ATAN2(-9, 8) As Result;
Output
This will produce the following result −
| Result |
|---|
| -0.844153986113171 |
Example
Here, we are using the MySQL ATAN2() function to return the arctangent of two numbers −
SELECT ATAN2(-9, 8) As Result;
The output for the query above is produced as given below −
| Result |
|---|
| -0.844153986113171 |
Example
You can also pass pi() function as a value to the ATAN2() function as shown below −
SELECT ATAN2(pi(), pi()) As Result;
Output
This will produce the following result −
| Result |
|---|
| 0.7853981633974483 |
Example
The arc tangent value is 0 if the values of both parameters of ATAN2() function is 0 −
SELECT ATAN2(0, 0) As Result;
Output
On executing the given query, the output is displayed as follows −
| Result |
|---|
| 0 |