[英]Function not producing intended results?
I am having some trouble trying to figure out why one of my functions isn't producing the results I expect. 我在尝试弄清楚为什么我的一个功能没有产生期望的结果时遇到了麻烦。 I am pretty sure it has something to do with converting this equation into code but I can't pinpoint what is wrong exactly. 我很确定这与将等式转换为代码有关,但是我无法确切指出到底出了什么问题。
This is the given formula: d=radius * arccos(sin(x1)sin(x2)+cos(x1)cos(x2)cos(|y1-y2|)) http://img42.com/yfTmc+ 这是给定的公式: d =半径* arccos(sin(x1)sin(x2)+ cos(x1)cos(x2)cos(| y1-y2 |))http://img42.com/yfTmc+
Here is my code: 这是我的代码:
part1 = math.cos(abs(y1 - y2))
part2 = math.cos(x1) * math.cos(x2)
part3 = math.sin(x1) * math.sin(x2)
d = RADIUS * math.acos(part3 + (part2 * part1))
return d
You're giving your values in degrees instead of the radians that the math.sin
, etc. functions expect. 您将以度为单位给出值,而不是math.sin
等函数期望的弧度。 Try converting your values to radians with math.radians(degValue)
. 尝试使用math.radians(degValue)
将值转换为弧度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.