我正在编写一个计算物体移动距离的程序,但是当我运行该程序时,使用45作为角度(sin45和cos45是等效的),输出的垂直高度和水平高度不同
import math
angle = float(input("Enter Angle of Movement(In Degrees): "))
print("Angle is: ",angle,"°")
horizontal_distance = (abs(overall_distance*math.sin(90-angle)))
print("Horizontal Distance:",horizontal_distance,"m")
vertical_distance = (abs(overall_distance*math.cos(90-angle)))
print("Vertical Distance:",vertical_distance,"m")发布于 2020-11-02 02:54:11
正弦和余弦的输入值以弧度为单位,而不是度。
发布于 2020-11-02 02:57:39
输入使用弧度单位,而不是度数。这是文档- https://docs.python.org/3/library/math.html。
相反,您应该将sin(90角度)替换为sin(math.pi/2角度)。
更新:刚刚看到你的帖子,关于将度数转换为弧度。您可以使用math.radians(学位)
发布于 2020-11-02 03:05:54
对于第二个问题
import math
x = math.radians(float(input()))
y = math.radians(float(input()))
SIN = math.sin(x)
COS = math.cos(y)
print(x)
print(y)
print(SIN)
print(COS)
45 
45
0.7853981633974483
0.7853981633974483
0.7071067811865476
0.7071067811865476https://stackoverflow.com/questions/64635695
复制相似问题