1. 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?

2. Re: Finding the heading (NSEW) between 2 points?

The homework is strong in this one...

3. 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.

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.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

Featured