Question Finding the heading (NSEW) given two points

Joined
Feb 26, 2012
Messages
11
Location
Visalia, California, United States
Programming Experience
10+
A 2D object has an x/y location, x/y direction, and a velocity.
During each update, 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, from 0 to 360) between it's current location, and it's next location, and then use that to determine it's heading (N, S, E, W, NE, NW, SE, or SW)?
 
This is a maths problem, not a programming problem. How would you do it with pen and paper? It's simple trigonometry. You would do it the same way in VB. Once you have determined what the application has to do, i.e. the maths, then the implementation of that logic in VB code is a programming problem that we can help you with. Once you get to that point, feel free to post back with specific implementation questions.

Note that trig functions can be found in the Math class. It's also important to note that those functions work with radians, not degrees. You should know how to convert between radians and degrees from high school maths class. You will find the Math.PI constant useful in this regard.
 
Back
Top