Open In App

ATAN() and ATAN2() Function in MySQL

Last Updated : 25 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

1. ATAN() Function :
ATAN() function in MySQL is used to return the arc tangent of any number x. The arctangent of x is defined as the inverse tangent function of x when x is real (x∈ℝ).

When the tangent of y is equal to x :

tan y = x

Then the arctangent of x is equal to the inverse tangent function of x, which is equal to y :

arctan x= tan-1 x = y

Syntax :

ATAN(X)

Parameter : This method accepts one parameter as mentioned above and described below :

  • X : A number whose arc tangent we want to calculate.

Returns : It returns the arc tangent of given number x.

Example-1 : Arc tangent of 1 using ATAN() function.

SELECT ATAN(1) AS Atan_Val ;

Output :

Atan_Val
0.7853981633974483

Example-2 : Arc tangent of  0 using ATAN() function.

SELECT ATAN(0) AS Atan_Val ;

Output :

Atan_Val
0

Example-3 : Arc tangent of  a +ve number in the range(0, -1)  using ATAN() function.

SELECT ATAN(0.35) AS Atan_Val ;

Output :

Atan_Val
0.33667481938672716

Example-4 : Arc tangent of  a -ve numbe using ATAN() function.

SELECT ATAN(-2.75) AS Atan_Val ;

Output :

Atan_Val
-1.2220253232109897

Example-5 : Arc tangent value of a numeric column in a table.

Table – Number :

X
-10
-1
-0.50
0
0.50
1
14
SELECT X, ATAN(X) AS ArcTan_X  FROM Number ;

Output :

X ArcTan_X
-10 -1.4711276743037347
-1 -0.7853981633974483
-0.50 -0.4636476090008061
0 0
0.50 0.4636476090008061
1 0.7853981633974483
14 1.4994888620096063

2. ATAN2() Function :
ATAN2() function in MySQL is used for return the arc tangent between specified two number, i.e., x and y. It returns the angle between the positive x-axis and the line from the origin to the point (y, x).

Syntax :

ATAN2 (Y, X)

Parameter : This method accepts one parameter as mentioned above and described below :

  • Y, X : Two number whose arc tangent we want to calculate.

Returns : It returns the angle between the positive x-axis and the line from the origin to the point (y, x).

Example-1 : Arc tangent of two negative number using ATAN2() function.

SELECT ATAN2(-5.44, -10.5 ) AS Atan2_Val ;

Output :

Atan2_Val
-2.6635738706445093

Example-2 : Arc tangent of two +ve number using ATAN2() function.

SELECT ATAN2( 20.35, 5.60 ) AS Atan2_Val ;

Output :

Atan2_Val
1.3022588047897063

Example-3 : Arc tangent value of two numeric column in a table.

Table – Number :

X Y
3.5 2.5
-7.8 5
6.7 -1.2
-55.00 -12.00
SELECT X, Y, ATAN2(X, Y) AS ArcTan2_XY  FROM Number ;

Output :

X Y ArcTan2_XY
3.5 2.5 0.9505468408120752
-7.8 5 -1.0007558630951863
6.7 -1.2 -1.748021711744616
-55.00 -12.00 -1.7856117271965553

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads