注意:我正在使用Lua。给定一个圆圈上的两个点相对于他们的度数,他们之间的度数是多少?
所以,我试图找出圆上两点之间的度数。问题是像340和20,其中正确答案是40度,但是做这样的事情
function FindLeastDegrees(s, f)
return ((f - s+ 360) % 360)
end
print(FindLeastDegrees(60, 260))
-- S = Start, F = Finish (In degrees)
其中一期工程只是试图找出两者之间的距离,当所有的一切情况之间。这下面的代码是我下一次失败的尝试。
function FindLeastDegrees(s, f)
local x = 0
if math.abs(s-f) <= 180 then
x = math.abs(s-f)
else
x = math.abs(f-s)
end
return x
end
print(FindLeastDegrees(60, 260))
我然后设法:
function FindLeastDegrees(s, f)
s = ((s % 360) >= 0) and (s % 360) or 360 - (s % 360);
f = ((f % 360) >= 0) and (f % 360) or 360 - (f % 360);
return math.abs(s - f)
end
print(FindLeastDegrees(60, 350))
--> 290 (Should be 70)
这样失败了。 :/
那么如何找到两个其他度数之间的最短度数,然后如果你应该顺时针或逆时针(加或减)来到那里。我完全困惑。
的什么,我试图做一些例子...
FindLeastDegrees(60, 350)
--> 70
FindLeastDegrees(-360, 10)
--> 10
这似乎这么难!我知道我将不得不使用...
- 模
- 绝对值?
我也想要它返回,如果我应该增加或减去获得值'完成'。
对不起,冗长的说明,我想你也许已经知道了....:/
这是链接http://stackoverflow.com/questions/16460311/determine-angle-between-two-points-on-a-circle-with-respect-to-center/16460479#16460479 – 2013-05-09 11:40:29