
Feb 29th, 2012, 12:38 PM
#1
Thread Starter
New Member
Finding the heading (NSEW) between 2 points?
A 2D sprite has an x/y location, x/y direction, and x/y velocity.
During each update call, its location = (location + (direction * velocity)).
This enables it to travel in any and all directions at varying speeds.
Using this information, how would you find the angle (in degrees) between it's current location, and it's next location?

Feb 29th, 2012, 10:38 PM
#2
Re: Finding the heading (NSEW) between 2 points?
The homework is strong in this one...

Mar 1st, 2012, 01:04 AM
#3
Thread Starter
New Member
Re: Finding the heading (NSEW) between 2 points?
The productivity is strong in that comment...
And yes, I've done my homework. I've calculated the normalized dot product and found it's inverse cosign, which gives me the angle in radians. If I converted that value to degrees, it would only be between 0 and 90 and then it would reset to 0. So this is an issue with quadrants, which I don't know how to solve. Thus, why I came here to find answers or other possible algorithms.
Thanks for the help.

Mar 1st, 2012, 02:24 AM
#4
Re: Finding the heading (NSEW) between 2 points?
The inverse cosine will give you angles between 0 and 180, not 0 and 90, degrees. The most direct solution is the "atan2" function; there's a Wikipedia page on it. You can also extend your inverse cosine method to handle quadrant issues without too much trouble by simply branching if the y component of the difference is negative. I can give more details if you need, but they're so simple I won't write them unless asked.
The time you enjoy wasting is not wasted time.
Bertrand Russell
< Remember to rate posts you find helpful.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
Survey posted by VBForums.
