Python 中将角度值从弧度转换为度数时出错

Error while converting value of angle to degrees from radians in Python

我正在尝试在 Python 中编写弹丸运动程序,同时输入水平速度和垂直速度的值,如果我直接在程序中输入确定的常数值,我会得到正确的结果。

但是当我使用代码让用户输入以度为单位的角度值时,(显然将 numpy 导入为 np),我得到的答案非常小($45^{\circ}$ 的值以 $-0.0001...$ 而不是 $40.8$ 的形式出现,当我在程序中手动输入速度分量的值时,它会正确显示。

这是我摘录的程序供参考,

thetaVal = input("Please enter theta value in degrees: ")
theta_val = float(thetaVal)
t = theta_val *180/3.14

v_x0= v_0*np.cos(t)
v_y0= v_0*np.sin(t)

我想不明白我哪里错了,是我的转换方式不对还是代码的语句优先级有问题,我真的想不通。

如有任何帮助,我们将不胜感激!

Numpy 的 cos 和 sin 函数采用以弧度为单位的角度。要将度数转换为弧度,您可以编写

t = theta_val * 3.14 / 180

或者更好,

t = np.radians(theta_val)

或等效

t = np.deg2rad(theta_val)