如何使用 Python 将弧度转换为度数? [英] How can I convert radians to degrees with Python?
问题描述
在 math
模块中,我可以只找到 math.cos(x)
,和 cos/sin/tan/acos/asin/atan.这将以弧度返回答案.我怎样才能得到度数的答案?
这是我的代码:
导入数学x = math.cos(1)y = x * 180/math.pi打印(y)30.9570417874
我的计算器,在 deg,给了我:
cos(1)0.9998476...
Python 在 math
包中包含两个函数;radians
将度数转换为弧度,和 degrees
将弧度转换为度数.
要匹配您需要的计算器的输出:
<预><代码>>>>math.cos(math.radians(1))0.9998476951563913请注意,所有三角函数都在角度和三角形两侧的比率之间进行转换.cos、sin 和 tan 以弧度为单位的角度作为输入并返回比率;acos、asin 和 atan 将比率作为输入并返回以弧度为单位的角度.你只转换角度,而不是比例.
In the math
module, I could only find math.cos(x)
, with cos/sin/tan/acos/asin/atan. This returns the answer in radians. How can I get the answer in degrees?
Here's my code:
import math
x = math.cos(1)
y = x * 180 / math.pi
print(y)
30.9570417874
My calculator, on deg, gives me:
cos(1)
0.9998476...
Python includes two functions in the math
package; radians
converts degrees to radians, and degrees
converts radians to degrees.
To match the output of your calculator you need:
>>> math.cos(math.radians(1))
0.9998476951563913
Note that all of the trig functions convert between an angle and the ratio of two sides of a triangle. cos, sin, and tan take an angle in radians as input and return the ratio; acos, asin, and atan take a ratio as input and return an angle in radians. You only convert the angles, never the ratios.
这篇关于如何使用 Python 将弧度转换为度数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!