Calculate coordinates between startpoint and endpoint
Given..
1 - The start-point GPS coordinates,
2 - The end-point GPS coordinates, 3 - The speed at which th开发者_运维技巧e 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?
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.
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
精彩评论