Hey Rynhardt! Yes, you're right and thanks for posting. :) It's funny as I'd tried this method some time ago with a GPS app I'm working on and it seemed to fail at times in that context, (which is why I posted mine) so I chalked it up to my blonde sleep-deprived brain at the time! lol! -So I'd abandoned it in favor of my more round-about way, but there ya go.
I'm glad I'm a way better model than mathematician! lol! -Actually to be fair, I tend to think in working with data after it is output rather than manipulating it as it is input, so it's not always my strong suit. :) Thanks again for confirming though. this brings up a good point though. Some languages actually do reverse these parameters natively so it's really important to know which ones do so that you can understand / work with your results. Have a great evening! You rock!… Smiles, Cara :) On Jan 19, 2011, at 2:24 PM, Rynhardt Kruger wrote: Hi Cara, One thing I've found is that you can get the same result by swapping the arguments to atan2. Using your variable names, angle=atan2(vectorX,vectorY)*180/M_PI; if (angle<0) angle+=360; Take care, Rynhardt * Cara Quinn <caraqu...@draconisentertainment.com> [110119 23:47]: > Thomas et al; > > It occurred to me, that during our last discussion of 3D mapping etc, that > you'd asked how I was converting my arc tangent result to a bearing with zero > being north and degrees ascending clockwise. Here's how I do it. this is my > own way, and is only for a flat plane which is perfect for games. There are > other formulae out there, but they take into account earth curvature. This is > not as elegant as I'd like, but is less expensive than other formulae. > -Perhaps someone else knows of a better formula?? -Would love to hear!? :) > > Anyway, this way is very simple. Hope it helps! :) > > Smiles, > > Cara :) > > // x1, y1 is the user's origin and x2, y2 is the point you're trying to get > the angle to. > > // subtract the remote point from your origin > // it's important to do this in this order or the result will be opposite > what you want > // I.E. 270 degrees instead of 90 etc > > double vectorX = x2 - x1; > double vectorY = y2 - y1; > > // get the angle in degrees between the two points > > double angle = (atan2(vectorY, vectorX) * 180 / 3.1415926535); > > // get the value in the proper negative range > > angle-= 450; > > // switch to positive so that degrees will ascend clockwise as with a > proper heading > > angle = angle * -1; > > // round off result so modulus will be accurate > > angle = round(angle); > > // use modulus of 360 to get result in the proper range > > angle = (int)angle % 360; > > // return the result; > > return angle; > --- > Gamers mailing list __ Gamers@audyssey.org > If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org. > You can make changes or update your subscription via the web, at > http://audyssey.org/mailman/listinfo/gamers_audyssey.org. > All messages are archived and can be searched and read at > http://www.mail-archive.com/gamers@audyssey.org. > If you have any questions or concerns regarding the management of the list, > please send E-mail to gamers-ow...@audyssey.org. --- Gamers mailing list __ Gamers@audyssey.org If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org. You can make changes or update your subscription via the web, at http://audyssey.org/mailman/listinfo/gamers_audyssey.org. All messages are archived and can be searched and read at http://www.mail-archive.com/gamers@audyssey.org. If you have any questions or concerns regarding the management of the list, please send E-mail to gamers-ow...@audyssey.org. --- Gamers mailing list __ Gamers@audyssey.org If you want to leave the list, send E-mail to gamers-unsubscr...@audyssey.org. You can make changes or update your subscription via the web, at http://audyssey.org/mailman/listinfo/gamers_audyssey.org. All messages are archived and can be searched and read at http://www.mail-archive.com/gamers@audyssey.org. If you have any questions or concerns regarding the management of the list, please send E-mail to gamers-ow...@audyssey.org.