我正在尝试找到由x轴与x轴连接点的线所形成的角度。所以实际上我试图找到普通的旧棕褐色反转。 这是我在Python 3中使用的代码
angle_with_x_axis = math.atan(y_from_centre / x_from_centre)
我正在point(1,1)
作为y_from_centre
和x_from_centre
进食,我得到了
0.7853981633974483
我的预期结果是45,但很自然。 我在这里做错了什么?
答案 0 :(得分:8)
math模块以弧度运行。 0.785弧度是45度。来自文档:
math.atan(x)的
以弧度为单位返回x的反正切。
答案 1 :(得分:6)
math
使用弧度。对于学位使用math.degrees
:
>>> math.degrees(math.atan(1))
45.0
答案 2 :(得分:2)
math.atan()
函数 - 以及math
模块中的许多其他函数 - 以弧度返回结果。文件明确指出:
以弧度返回x的反正切,。
(强调我的)
math
模块提供了一种将弧度转换为度数的方法,反之亦然:
>>> import math
>>> math.degrees(math.atan(1))
45.0
>>>
>>> math.radians(45.0)
0.7853981633974483
>>>
您还可以创建一个辅助函数来包装此逻辑:
>>> def atan_in_degress(x):
... return math.degrees(math.atan(x))
...
>>> atan_in_degress(1)
45.0
>>> atan_in_degress(2)
63.43494882292202
>>>