Convert radian to degree python

View Discussion

Improve Article

Save Article

  • Read
  • Discuss
  • View Discussion

    Improve Article

    Save Article

    degrees() and radians() are methods specified in math module in Python 3 and Python 2. 
    Often one is in need to handle mathematical computation of conversion of radians to degrees and vice-versa, especially in the field of geometry. Python offers inbuilt methods to handle this functionality. Both the functions are discussed in this article.

    radians()

    This function accepts the “degrees” as input and converts it into its radians equivalent. 
     

    Syntax : radians(deg) Parameters : deg : The degrees value that one needs to convert into radians Returns : This function returns the floating point radians equivalent of argument. Computational Equivalent : 1 Radians = 180/pi Degrees.

      Code #1 : Demonstrating radians() 

    Python3

    import math

    print("180 / pi Degrees is equal to Radians : ", end ="")

    print (math.radians(180 / math.pi))

    print("180 Degrees is equal to Radians : ", end ="")

    print (math.radians(180))

    print("1 Degrees is equal to Radians : ", end ="")

    print (math.radians(1))

    Output:

    180/pi Degrees is equal to Radians : 1.0
    180 Degrees is equal to Radians : 3.141592653589793
    1 Degrees is equal to Radians : 0.017453292519943295

    degrees()

    This function accepts the “radians” as input and converts it into its degrees equivalent. 
     

    Syntax : degrees(rad) Parameters : rad : The radians value that one needs to convert into degrees. Returns : This function returns the floating point degrees equivalent of argument. Computational Equivalent : 1 Degrees = pi/180 Radians.

      Code #2 : Demonstrating degrees() 

    Python3

    import math

    print("pi / 180 Radians is equal to Degrees : ", end ="")

    print (math.degrees(math.pi / 180))

    print("180 Radians is equal to Degrees : ", end ="")

    print (math.degrees(180))

    print("1 Radians is equal to Degrees : ", end ="")

    print (math.degrees(1))

    Output:

    pi/180 Radians is equal to Degrees : 1.0
    180 Radians is equal to Degrees : 10313.240312354817
    1 Radians is equal to Degrees : 57.29577951308232

    Application : There are many possible applications of these functions in mathematical computations related to geometry and has a certain applications in astronomical computations as well.


    Python convert radians to degrees or degrees to radians:

    What are Radians and what problem does it solve?:

    Radians and degrees are two separate units of measure that help people express and communicate precise changes in direction. Wikipedia has some great intuition with their infographics on how one Radian is defined relative to degrees:

    https://en.wikipedia.org/wiki/Radian

    Convert radian to degree python

    Python examples using libraries calculating degrees from radians:

    >>> import math
    >>> math.degrees(0)                       #0 radians == 0 degrees
    0.0
    >>> math.degrees(math.pi/2)               #pi/2 radians is 90 degrees
    90.0
    >>> math.degrees(math.pi)                 #pi radians is 180 degrees
    180.0      
    >>> math.degrees(math.pi+(math.pi/2))     #pi+pi/2 radians is 270 degrees
    270.0 
    >>> math.degrees(math.pi+math.pi)         #2*pi radians is 360 degrees
    360.0      
    

    Python examples using libraries calculating radians from degrees:

    >>> import math
    >>> math.radians(0)           #0 degrees == 0 radians
    0.0
    >>> math.radians(90)          #90 degrees is pi/2 radians
    1.5707963267948966
    >>> math.radians(180)         #180 degrees is pi radians
    3.141592653589793
    >>> math.radians(270)         #270 degrees is pi+(pi/2) radians
    4.71238898038469
    >>> math.radians(360)         #360 degrees is 2*pi radians
    6.283185307179586
    

    Source: https://docs.python.org/3/library/math.html#angular-conversion

    The mathematical notation:

    Convert radian to degree python

    You can do degree/radian conversion without python libraries:

    If you roll your own degree/radian converter, you have to write your own code to handle edge cases.

    Mistakes here are easy to make, and will hurt just like it hurt the developers of the 1999 mars orbiter, who sunk $125m dollars crashing it into Mars because of non intuitive edge case here.

    >>> 0 * 180.0 / math.pi                         #0 radians is 0 degrees
    0.0
    >>> (math.pi/2) * 180.0 / math.pi               #pi/2 radians is 90 degrees
    90.0
    >>> (math.pi) * 180.0 / math.pi                 #pi radians is 180 degrees
    180.0
    >>> (math.pi+(math.pi/2)) * 180.0 / math.pi     #pi+(pi/2) radians is 270 degrees
    270.0
    >>> (2 * math.pi) * 180.0 / math.pi             #2*pi radians is 360 degrees
    360.0
    

    Degrees to radians:

    >>> 0 * math.pi / 180.0              #0 degrees in radians
    0.0
    >>> 90 * math.pi / 180.0             #90 degrees in radians
    1.5707963267948966
    >>> 180 * math.pi / 180.0            #180 degrees in radians
    3.141592653589793
    >>> 270 * math.pi / 180.0            #270 degrees in radians
    4.71238898038469
    >>> 360 * math.pi / 180.0            #360 degrees in radians
    6.283185307179586
    

    Expressing multiple rotations with degrees and radians

    Single rotation valid radian values are between 0 and 2*pi. Single rotation degree values are between 0 and 360. However if you want to express multiple rotations, valid radian and degree values are between 0 and infinity.

    >>> import math
    >>> math.radians(360)                 #one complete rotation
    6.283185307179586
    >>> math.radians(360+360)             #two rotations
    12.566370614359172
    >>> math.degrees(12.566370614359172)  #math.degrees and math.radians preserve the
    720.0                                 #number of rotations
    

    Collapsing multiple rotations:

    You can collapse multiple degree/radian rotations into a single rotation by modding against the value of one rotation. For degrees you mod by 360, for radians you modulus by 2*pi.

    >>> import math
    >>> math.radians(720+90)        #2 whole rotations plus 90 is 14.14 radians
    14.137166941154069
    >>> math.radians((720+90)%360)  #14.1 radians brings you to 
    1.5707963267948966              #the end point as 1.57 radians.
    
    >>> math.degrees((2*math.pi)+(math.pi/2))            #one rotation plus a quarter 
    450.0                                                #rotation is 450 degrees.
    >>> math.degrees(((2*math.pi)+(math.pi/2))%(2*math.pi)) #one rotation plus a quarter
    90.0                                                    #rotation brings you to 90.
    

    Fundamental education on Radians and Degrees

    5 minute refresher using Trigonometry and expression of rotation to convert radians to degrees and back: https://youtu.be/ovLbCvq7FNA?t=31

    Khan academy refresher on trigonometry, unit circle, angular mathematics to use sin,cos,tan to describe rotation and changes in rotation. https://www.khanacademy.org/math/algebra2/x2ec2f6f830c9fb89:trig/x2ec2f6f830c9fb89:unit-circle/v/unit-circle-definition-of-trig-functions-1

    Which function is used to convert an angle from radians into degrees in Python?

    degrees() Function This function takes radian value as parameter and return the equivalent value in degrees. The return is a float value.

    How do you convert from radians to degrees?

    From the latter, we obtain the equation 1 radian = (180π)o . This leads us to the rule to convert radian measure to degree measure. To convert from radians to degrees, multiply the radians by 180°π radians .

    Does Python work in degrees or radians?

    Python includes two functions in the math package; radians converts degrees to radians, and degrees converts radians to degrees. Note that all of the trig functions convert between an angle and the ratio of two sides of a triangle.

    How do you convert a number to a degree in Python?

    The mmath. degrees() method converts an angle from radians to degrees. Tip: PI (3.14..) radians are equal to 180 degrees, which means that 1 radian is equal to 57.2957795 degrees.