SQLite ATAN2() Function
The SQLite ATAN2() function returns arc tangent of two numbers. This function uses sign of both numbers to determine the quadrant for the result.
Syntax
ATAN2(y, x)
Parameters
y |
Required. Specify the first number used to calculate the arc tangent. |
x |
Required. Specify the second number used to calculate the arc tangent. |
Return Value
Returns the arc tangent of two numbers.
Example 1:
The example below shows the usage of ATAN2() function.
SELECT ATAN2(PI(), 2); Result: 1.00388482185389 SELECT ATAN2(3, 5); Result: 0.540419500270584 SELECT ATAN2(2, 2); Result: 0.785398163397448 SELECT ATAN2(2, -2); Result: 2.35619449019234 SELECT ATAN2(-2, 2); Result: -0.785398163397448 SELECT ATAN2(-2, -2); Result: -2.35619449019234
Example 2:
Consider a database table called Sample with the following records:
Data | y | x |
---|---|---|
Data 1 | 10 | 10 |
Data 2 | -10 | 10 |
Data 3 | 10 | -10 |
Data 4 | -10 | -10 |
To calculate the arc tangent of records of column y and column x, the following query can be used:
SELECT *, ATAN2(y, x) AS ATAN2_Value FROM Sample;
This will produce the result as shown below:
Data | y | x | ATAN2_Value |
---|---|---|---|
Data 1 | 10 | 10 | 0.785398163397448 |
Data 2 | -10 | 10 | -0.785398163397448 |
Data 3 | 10 | -10 | 2.35619449019234 |
Data 4 | -10 | -10 | -2.35619449019234 |
❮ SQLite Functions