Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBP] Find the angle between two bearings

Author
Message
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 16th Aug 2007 19:01


I'm sure this can be accomplished much easier using the vector commands (if so, please show me how) - but what this does is calculate the difference between two angles (including situations like 359 degrees and 1 degree, where simply subtracting one from the other would give 358 instead of the correct result of 2).

Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 17th Aug 2007 01:39 Edited at: 17th Aug 2007 01:43
I wrote that exact function like that for the codebase not too long ago, what a coinincidence. Not trying to brag but mine's a little easier to understand...

http://codebase.dbp-site.com/code/find-difference-between-two-angles-25

Quote: "Quote: "he probably thought you meant you thought"
NOO!! MY BRAIN IT EXPL"
Ric
20
Years of Service
User Offline
Joined: 11th Jul 2004
Location: object position x
Posted: 17th Aug 2007 01:56
Looks like we've both been outdone - Diggsey posted this in another thread:



It appears to work, and in a single line too!

Code Dragon
18
Years of Service
User Offline
Joined: 21st Aug 2006
Location: Everywhere
Posted: 17th Aug 2007 14:22
Very clever trick if you ask me, tricking the wrapvalue function into returning 180 minus the angle difference. (I think that's how it works) My brain would have hurt less figuring it out if it was like this though:



Quote: "Quote: "he probably thought you meant you thought"
NOO!! MY BRAIN IT EXPL"
Ankillito
17
Years of Service
User Offline
Joined: 10th Dec 2006
Location: Litigious California
Posted: 18th Aug 2007 09:09
Woot! Thx Diggsey! And Ric for pointing it out! Any idea how many times my apps crashed because of some bug in my angle function?

http://forum.thegamecreators.com/xt/xt_apollo_pic.php?i=1234759
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 20th Aug 2007 22:00

It finds the relative angle between the two, offsets it by 180 so that close angles are around 180, and won't be affected by the wrapvalue. Offsetting it back again gives the relative angle in the range of -180 to +180, and a simple abs will turn it into a distance

Login to post a reply

Server time is: 2024-11-22 18:24:25
Your offset time is: 2024-11-22 18:24:25