4 Unique Ways To Convert Radians to Degrees in Python

Mathematically we are all familiar with radians and degrees. Radians are something that intercepts an arc on the circle equal in length. A degree is a unit of the angle of measurement. And we also know that how to convert the radians to degrees. Now let us think about how to implement it in python. There are four unique ways available to convert radians to degrees in python. In this article, we will learn all the four possible ways.

A complete revolution of a circle in anticlockwise is represented by 2π in radians, and we can describe it in degree as 360o. Based on this statement, we can define the equation as 2π=360o. And also π=180o. So from this, we can easily say that π radian is equal to 180 degrees. 

Methods to convert radians to degrees:

  • Normal method using formula
  • Using degrees() function
  • By numpy.degree()
  • Using np.rad2deg()

Method 1: Using the formula to convert radians to degrees in python

There is a standard method available to convert radians to degrees using a formula. We can implement this method by function. The conversion formula is:

Degree = (Radian X π )/180

Code to convert radians to degrees in python

import math
def degree_converter(x):
    pi_value=math.pi
    degree=(x*180)/pi_value
    return degree
print("The degree of the given radian is :",degree_converter(1.5708))

Import math. Create a function named degree, including a pi value. I am using the above-given formula to calculate the degree of the given radian. Return the value of the degree.

Output

The degree of the given radian is : 90.0002104591497

Method 2: Using degrees() function to convert radians to degrees in python

degrees() is a built-in function that is already available in python. This will convert the given radians into degrees.

Syntax

math.degrees(radian value)

Parameter

Radian value: input radian values

Returns

Degree of the given radian value

Code to convert radians to degrees in python

import math 
radians = 1.5708
degrees = math.degrees(radians)
print("The degree of the given radian is :",degrees)

Import a math function. Use the built-in function to get the degrees of the given radian. Print the degrees.

Output

The degree of the given radian is: 90.00021045914971

Method 3:Using numpy.degrees() to convert radians to degrees in python

We can also use the numpy module to convert the radians to degrees. numpy.degrees() is a function that is useful to get the degrees of the given radians. This is one of the built-in functions in the numpy module.

Syntax

numpy.degrees(x/out=None*where=Truecasting='same_kind'order='K'dtype=Nonesubok=True[, signatureextobj]) = <ufunc 'degrees'>

Parameters

  • x: Input radian
  • out: A memory to store the result
  • where: array-like
  • **kwargs: For other keyword-only arguments, see the ufunc docs.

Returns

Degree value of the given radian

Code

import numpy
radian = 1.5708 
degrees=numpy.degrees(radian)
print("The degree of the given radian is:",degrees)

Import a numpy module. Declare a variable radian. Assign a value for the radian variable. Use the numpy.degrees() function. Print the value of the degrees.

Output

The degree of the given radian is: 90.00021045914971

Method 4: Using np.deg2rad to convert radians to degrees in python

In numpy, there is another function available to convert the radian to degrees. That is np.rad2deg function. This is a function available in the numpy module.

Syntax

numpy.rad2deg(x, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj]) = <ufunc 'rad2deg'>

Parameters

  • x: Input radian
  • out: A memory to store the result
  • where: array-like
  • **kwargs: For other keyword-only arguments, see the ufunc docs.

Returns

Degrees of the given radian

Code

import numpy as np
radian = 1.5708 
degrees=np.rad2deg(radian)
print("The degree of the given radian is :",degrees)

Import a numpy module as np. Give an input radian. Use the np.rad2deg function. Print the degree.

Output

The degree of the given radian is : 90.00021045914971

Bonus section: How to convert degrees to radians

So far, we have entirely learned how to convert the radian values to degrees. As additional knowledge, we will learn the reverse process, that is, degrees to radians. We will now know how to get the radians for the values of the given degree. We will use math.radians() function to get the radians of the given values.

Code

import math 
degrees = 90
radians = math.radians(degrees)
print("The radian value is:",radians)

Import a necessary module. Here we need to import a math module. Give the input degrees. Use the radians() function to get the radians. This function will return the radian value for the given degree. Print the result.

Output

The radian value is: 1.5707963267948966

1. How many possible ways are there to convert the radians to degrees in python?

There are four possible ways to convert the radians to degrees in python namely, math.degrees(), numpy.degree(), numpy.rad2degree() and custom function.

2. What are the ways to convert the radians to degrees?

We can convert the radians to degrees by a normal method using the formula, degrees() function, numpy.degrees(), and np.rad2deg() function.

3. How to print degree sign in python?

degree_symbol= u’\N{DEGREE SIGN}’
print(degree_symbol)

Conclusion

In this article, we have learned how to get the degree value by using radian values in python. Learn all the four methods to get the degree values. While learning something, try to know all the possible ways. That is the way to become a good programmer. Try to solve the programs on your own.

In case of any queries, let us know in the comment section. We will help you. Learn python with us. Shine in your way. Happy coding.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments