2024-09-27 07:30:01 发布
网友
你知道为什么下面的代码会产生错误的计算吗?可能只是语法不正确
import math ax = distance1 * math.cos(direction1)
distance1设置为7600。 并且direction1被设置为113
distance1
direction1
在普通计算器中,113的余弦的7600倍等于-2969.556576518480538.
-2969.556576518480538.
但是上面的代码产生7564.02643525
7564.02643525
math.cos和其他三角函数take arguments in radians,而不是度。可以使用math.radians进行转换
math.cos
math.radians
ax = distance1 * math.cos(math.radians(direction1))
这会产生-2969.5565765184806如预期的那样
-2969.5565765184806
math.cos
和其他三角函数take arguments in radians,而不是度。可以使用math.radians
进行转换这会产生
-2969.5565765184806
如预期的那样相关问题 更多 >
编程相关推荐