Angular Conversion Functions



degrees() Function

The degrees() method converts angle x from radians to degrees.

Syntax

Following is the syntax for degrees() method −

degrees(x)

Note − This function is not accessible directly, so we need to import the math module and then we need to call this function using the math static object.

Parameters

  • x − This must be a numeric value.

Return Value

This method returns the degree value of an angle.

Example

The following example shows the usage of degrees() method −

from math import degrees, pi

x = 3
val = degrees(x)
print ("x: ",x, "degrees(x): ", val)

x = -3
val = degrees(x)
print ("x: ",x, "degrees(x): ", val)

x = 0
val = degrees(x)
print ("x: ",x, "degrees(x): ", val)

x = pi
val = degrees(x)
print ("x: ",x, "degrees(x): ", val)

x = pi/2
val = degrees(x)
print ("x: ",x, "degrees(x): ", val)

x = pi/4
val = degrees(x)
print ("x: ",x, "degrees(x): ", val)

When we run the above program, it produces the following output

x: 3 degrees(x): 171.88733853924697
x: -3 degrees(x): -171.88733853924697
x: 0 degrees(x): 0.0
x: 3.141592653589793 degrees(x): 180.0
x: 1.5707963267948966 degrees(x): 90.0
x: 0.7853981633974483 degrees(x): 45.0

radians() Function

The radians() function converts angle x from degrees to radians.

Syntax

Following is the syntax for radians() function −

radians(x)

Note − This function is not accessible directly, so we need to import the math module and then we need to call this function using the math static object.

Parameters

  • x − This must be a numeric value.

Return Value

This function returns radian value of an angle.

Example

The following example shows the usage of radians() method −

from math import radians, pi

x = 30
val = radians(x)
print ("x: ",x, "radians(x): ", val)

x = -30
val = radians(x)
print ("x: ",x, "radians(x): ", val)

x = 0
val = radians(x)
print ("x: ",x, "radians(x): ", val)

x = 90
val = radians(x)
print ("x: ",x, "radians(x): ", val)

x = 180
val = radians(x)
print ("x: ",x, "radians(x): ", val)

x = 45
val = radians(x)
print ("x: ",x, "radians(x): ", val)

When we run the above program, it produces the following output

x: 30 radians(x): 0.5235987755982988
x: -30 radians(x): -0.5235987755982988
x: 0 radians(x): 0.0
x: 90 radians(x): 1.5707963267948966
x: 180 radians(x): 3.141592653589793
x: 45 radians(x): 0.7853981633974483
python_maths.htm
Advertisements