degress()和radians()是在Python 3和Python 2中的math模塊中指定的方法。
通常需要處理弧度到度,反之亦然的數學計算,尤其是在幾何學領域。 Python提供了內置方法來處理此函數。本文討論了這兩種函數。
radians()
此函數接受“degrees”作為輸入並將其轉換為等效的弧度。
用法: radians(deg)
參數:
deg:需要轉換為弧度的度值
返回:此函數返回等效於參數的浮點弧度。
Computational Equivalent:1弧度= 180 /pi度。
代碼1:演示radians()
# Python code to demonstrate
# working of radians()
# for radians
import math
# Printing radians equivalents.
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))
輸出:
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()
此函數接受“radians”作為輸入並將其轉換為等效的度數。
用法: degrees(rad)
參數:
rad:需要轉換為度的弧度值。
返回:此函數返回等效於參數的浮點度。
Computational Equivalent:1度= pi /180弧度。
代碼2:演示degrees()
# Python code to demonstrate
# working of degrees()
# for degrees()
import math
# Printing degrees equivalents.
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))
輸出:
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
應用:
這些函數在與幾何相關的數學計算中有許多可能的應用,並且在天文計算中也有一定的應用。
相關用法
- Python numpy.radians()、deg2rad()用法及代碼示例
- Python numpy.degrees()、rad2deg()用法及代碼示例
- Python Set pop()用法及代碼示例
注:本文由純淨天空篩選整理自manjeet_04大神的英文原創作品 degrees() and radians() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。