views:

104

answers:

2

Given..

1 - The start-point GPS coordinates,
2 - The end-point GPS coordinates,
3 - The speed at which the object is travelling,
4 - Knowing that the trip trajectory will be a straight line...

How can I calculate what my GPS coordinated will be in n minutes' time? That is to say, how can I calculate my position at a given time after the trip has started before the trip has ended?

A: 

This method is accurate enough only for small distances, because the curvature of the Earth is not accounted for. You can convert pseudo-spherical coordinates to planar coordinates, but a different method would probably be better for cases where the distance is large and accuracy is needed.

The key is to calculate the total distance between the start and end points. You can use Euclidean distance but, as stated, this is reasonably accurate only for smaller distances:

distance = sqrt((end.x - start.x) ** 2 + (end.y - start.y) ** 2)

You then know how long it will take to travel the entire distance:

timeToTravelDistance = distance / speed

From this, you can calculate the percentage of the distance you have traveled from start to end given time:

percentageTraveled = time / timeToTravelDistance

Finally, interpolate:

result.x = start.x * (1 - percentageTraveled) + end.x * percentageTraveled
result.y = start.y * (1 - percentageTraveled) + end.y * percentageTraveled
strager
Your formulas aren't quite going to work as the Earth is not a flat plane. It's a three-dimensional object that resembles an ellipsoid. You can get pretty close by assuming it's a sphere and coming up with a meters/degree value, but the errors are going to grow large if the starting/ending coordinates are far away.
Matti Virkkunen
@Matti, This is true. However, the question explicitly states the trajectory is a straight line. There is no need to worry about the how the Earth is shaped because we are working on a single plane.
strager
@strager: I'd imagine that means a straight line along the Earth's surface (which is infact curved) Or are we digging tunnels here?
Matti Virkkunen
@Matti Virkkunen, If it's a straight line across the Earth's surface, then I *have* to assume that the "speed" is also "curved" (not sure how to explain it). In other words, you'd still treat it like a planar problem.
strager
Assuming that the given values (number of minutes and speed) are small, a 2D approximation is going to be pretty close (even if this is an airplane problem, your possible distance traveled in a few minutes is probably no more than 50 miles). However, if you want to get really exact, use the haversine formula: http://en.wikipedia.org/wiki/Haversine_formula.
Seth
@strager (re: curved speed) you're right: the shortest *path* in a gravitational field is generally parabolic. But it's really close to a straight line unless you're in a really strong gravitational field, or moving really fast, or traveling really far, etc. :D
Seth
-1: @Matti has pointed out repeatedly that the shortest distance between points on the Earth's surface is not a straight line. @strager is wrong to state that the surface of the Earth is a plane. But then I agree with @Seth that for short distances the 2D approximation will generally be satisfactory for all but the most demanding applications.
High Performance Mark
@High Performance Mark, I'm not saying the surface of the Earth is a place. I'm saying you can treat it as a plane to simplify this problem, because everything you're given is on the same (spherical-ish?) plane. Plus, as I mentioned before, I believe "straight line" is a literal straight line, and not e.g. a straight line along a sphere-ish shape.
strager
@strager: and it's because of your mistaken assertions about distances on the surface of the Earth that I downvoted your answer. Don't sweat the small stuff, I get downvoted all the time, it's all part of the rich SO experience.
High Performance Mark
@strager: I take my words back, this isn't even nearly accurate enough to ever be usable. Calculate the distance between the North Pole (90N 0E) and (0N 0E), and then the North Pole and (0N 90E) (thatis, one quarter along the Equator to the east). Then look at a picture of a sphere and see where you're going wrong (http://en.wikipedia.org/wiki/Geographic_coordinate_system). Not to mention that the Earth isn't even a sphere but an ellipsoid. Your method gives somewhat accurate results for very, very small distances, but for anything larger it starts getting very inaccurate.
Matti Virkkunen
After working things through, the method I provided doesn't work without some additional work transforming raw GPS coordinates to planar coordinates. I will add a notice that this solution only applies for smaller distances.
strager
+1  A: 

You need to use the Thaddeus Vincenty Formulae

This will give you the distance between two GPS co-ordinates (lon/lat).

Then simply do

  Time = [Distance] in m / [Speed] in m/s

Assuming uniform speed, its a gross estimation.

Darknight