MySQL RADIANS() and DEGREES() [With Easy Examples]

DEGREES And RADIANS

In this tutorial, we will study the MySQL RADIANS() and MySQL DEGREES() functions. You must have come across radians and degrees as the two measures of angles in mathematics. The measures of angles are fundamental to geometry.

Recommended read – MySQL SIN() and MySQL ASIN() functions

Seeing this need, MySQL provides us with two functions – RADIANS() and DEGREES()

  • The RADIANS() function takes in a degree value as input and converts it to its radians equivalent. 
  • The DEGREES() function does the exact opposite. It takes in a radians value as input and converts it to its degree equivalent.

Let us explore the syntax and examples of both these functions now.


Syntax of MySQL RADIANS()

RADIANS(number);Code language: SQL (Structured Query Language) (sql)

Where ‘number’ is the measure of an angle in degrees.


Syntax of MySQL DEGREES()

DEGREES(number);Code language: SQL (Structured Query Language) (sql)

Where ‘number’ is the measure of an angle in radians.


Examples of MySQL RADIANS()

Let us start by looking at a few basic examples. Let us find the value in radians of the following degree values – 120, 45 and 25.25 using the below queries.

SELECT RADIANS(120); 
SELECT RADIANS(45); 
SELECT RADIANS(25.25);Code language: SQL (Structured Query Language) (sql)

And we get the output as,

MySQL Radians Basic Example

MySQL RADIANS() With Negative Values

Let us now pass negative angle values in degrees to the RADIANS() function. Consider the below queries.

SELECT RADIANS(-25); 
SELECT RADIANS(-75.5);Code language: SQL (Structured Query Language) (sql)

And we get the output as,

MySQL Radians Negative Value

MySQL RADIANS() With Expressions

We can also pass expressions as arguments to RADIANS(). Expressions may contain mathematical operators or even mathematical functions like PI(). Let us see this using the below queries.

SELECT RADIANS(50/2); 
SELECT RADIANS(PI()/3);Code language: SQL (Structured Query Language) (sql)

And we get the output as follows.

MySQL Radians Expression

MySQL RADIANS() With NULL

RADIANS() returns NULL if we pass NULL as an argument to it since a degree value cannot be NULL. Let us see this using the below example.

SELECT RADIANS(NULL);Code language: SQL (Structured Query Language) (sql)

And we get the output as,

MySQL Radians Null

Examples Of MySQL DEGREES()

Let us now look at a few examples of MySQL DEGREES(). How about we start with finding the degree equivalent of the following radian values – 1, 1.25 and 0.5? The queries for it are –

SELECT DEGREES(1); 
SELECT DEGREES(1.25); 
SELECT DEGREES(0.5);Code language: SQL (Structured Query Language) (sql)

And we get the output as follows –

MySQL Degrees Basic Example

DEGREES() With Expressions

We can also pass expressions as arguments to the DEGREES() function. Expressions may contain mathematical operators or even mathematical functions like PI(). Let us see this using the below queries.

SELECT DEGREES(5/2); 
SELECT DEGREES(5*0.003);Code language: SQL (Structured Query Language) (sql)

And we get the output as,

MySQL Degrees Expression

As you would have come across in maths, most radian values are expressed in terms of 𝜋. Let us find the degree equivalent of some of the radian values expressed in 𝜋.

SELECT DEGREES(PI()/6); 
SELECT DEGREES(PI()); 
SELECT DEGREES(PI()/4);Code language: SQL (Structured Query Language) (sql)

And we get the output as follows –

MySQL Degrees Pi

DEGREES() With Negative Values

What if you pass a negative value to DEGREES()? Let us see an example of this.

SELECT DEGREES(-0.5); 
SELECT DEGREES(-PI()/2);Code language: SQL (Structured Query Language) (sql)

And we get the output as –

MySQL Degrees Negative Value

MySQL DEGREES() With NULL

MySQL DEGREES() returns NULL if we pass NULL as an argument to it since a radians value cannot be NULL. Let us see this using the below example.

SELECT DEGREES(NULL); Code language: SQL (Structured Query Language) (sql)

And we get the output as,

MySQL Degrees Null

MySQL DEGREES() and RADIANS() With Tables

Consider the below Angles table where the Angle column contains the measure of angles in radians.

Angles Table
Angles Table

Let us start by displaying the Angle column and its values equivalent in degrees. We do so using the below query.

SELECT Angle, DEGREES(Angle) AS AngleInDegrees FROM Angles;Code language: SQL (Structured Query Language) (sql)

And we get the output as,

Degrees Table Example 1

Let us cross-check the above output by passing the DEGREES() function inside the RADIANS() function. Yes, that is allowed. As I said, we can include any mathematical function as an argument to these functions. Anyway, our query is –

SELECT Angle, RADIANS(DEGREES(Angle)) AS AngleInRadians FROM Angles;Code language: SQL (Structured Query Language) (sql)

And the output is –

Degrees Table Example 2

Bingo! The values in both columns match.


Conclusion

Converting angle values from degree to radians and radians to degrees is an important operation. We as humans, find it easier to use the degree notation while expressing the measures of angles. However, the trigonometric functions like SIN() and so on, take the input of the measure of angles in radians only. Hence, these two functions prove quite important.


References