度数范围(0-360)环绕困境
我试图捕获距离给定度数(图:15)X 距离(图:45)的度数。我陷入了 360/0 环绕之中。给定的度数均标准化为 0-360。有人可以告诉我该怎么做吗?我附上了一张图表来说明我缺乏的才能。
我在迈克尔·杰克逊的坟墓上发誓,在提问之前我已经在 Google 和 StackOverflow 上搜索过答案。我意识到这可能是重复的,但回答的问题不得被适当标记或命名。
I'm trying to trap the degrees that are X distance (fig: 45) away from a given degree (fig: 15). I'm getting caught up in the 360/0 wrap around. The given degrees are all normalized 0-360. Can someone please show me how to do this? I've included a graphic that illustrates my lacking aptitude.
I swear on Michael Jackson's grave that I scoured Google and StackOverflow for an answer before asking. I realize this is probably a repeat but the answered ones must not be tagged or named appropriately.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
15+45=60,所以你的那一边是对的,但是 15-45=-30,所以你必须加上 360,得到 330。
基本上,每次你走出 [0,360) 时,你都会加上或减去 360,其中我' m 使用 a ) 表示开放范围。
如果您想编写测试以将标记着色为蓝色,假设 h 是标题,o 是偏移量,x 是我们正在测试的标记,那么您正在寻找类似 c-ish 伪代码的内容:
15+45=60, so you have that side right, but 15-45=-30, so you have to add 360, giving 330.
Basically, you add or subtract 360 each time you go outside [0,360), where I'm using a ) for an open range.
If you want to write the test to colour your markers blue, say h is the heading, o is the offset, and x is the marker we're testing, you're looking for something like, in c-ish pseudocode:
为什么不简单地使用模运算呢?
度=度% 360
Why not simply use the modulo operation?
deg = deg % 360
我不是 100% 确定你想要实现什么。我假设你想要的是:“对于 X 度,找到距它最多 Y 度的所有度数,在每个标记之间给出 Z 度的步长。”
既然如此,只需编写一个从 XY 到 X+Y 的 for 循环,以 Z 为增量。 0 然后只需添加 360。
I'm not 100% sure what you want to achieve. I'm assuming what you want is: "For degree X find all degrees that are at most Y degrees away from it give a step of Z degrees between each mark."
That being the case just write a for loop from X-Y to X+Y taking increments of Z. If the current degree value is < 0 then just add 360.