开发者

Degree range (0-360) wrap around woes

I'm try开发者_StackOverflow社区ing 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.

Degree range (0-360) wrap around woes


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:

t=h-x
if (t>360) {t-=360}
if (t<0) {t+=360}
if (t<o) {mark blue}


Why not simply use the modulo operation?

deg = deg % 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜