Calculating a Future Position
I've got this information about an entity:
Lat/Long Position Heading (In Radians) Speed (In knots)
How do I calculate where the entities lat/long position will be at an arbitrary point in time (or figure out its position at intervals) assuming that the e开发者_StackOverflowntity is moving in a straight line at a constant speed at a constant altitude?
(As you can tell, my math skills are weak)
First, you cannot move on a straight line and at the same time at a constant altitude. Your Lat/Long coordinates are over a reference ellipsoid (most likely WGS84). Their are various libraries or DB extensions that have a bunch of functions to do exactely these kinds of problems. Postgis for instance is one of them. Most of them are free and tested and do work. I would not recommend to try to implement this yourself (assuming the earth is a perfect sphere with radius r) as you must take into consideration the reference ellipsoid you are using.
Taking into consideration the answer provided by Hyperboreus, there is the aviation formulary here: http://williams.best.vwh.net/avform.htm that has formulas for calculating a new lat/lon given a starting point, and angle, and a distance. You would have to calculate the distance yourself. It sounds like you have everything you need to calculate the distance though, as speed is just distance / time, and if you multiply that by the time offset you want to use, you've got your distance.
1 knot = 1 NM / hr distance = yourTimeInDecimalHours * speed;
code sample to illustrate this (copied from the above referenced link):
double lat1 = 0, lon1 = 0; // NOTE: these are in radians - remember PI/2 radians = 90 degrees
double d = timeInDecimalHours * speedInKnots; // so a half hour at 35 knots would be .5 * 35
double tc = usersTrueCourse; // aka user's heading
double lat= // this will be in radians!!
Math.asin(
Math.sin(lat1)
* Math.cos(d)
+ Math.cos(lat1)
* Math.sin(d)
* Math.cos(tc)
);
double lon = 0;
if (Math.cos(lat) == 0) {
lon = lon1 // endpoint a pole
} else {
lon = (lon1 - Math.asin(Math.sin(tc)*Math.sin(d)/Math.cos(lat)) + Math.PI % (2*Math.PI))-Math.PI;
}
精彩评论