Formula to calculate change in distance to destination or origin of a straight-line path of travel

233 Views Asked by At

I am writing an application that consumes GPS data - and I am trying to calculate direction traveled based on a change in distance to the destination and origin.

Assume that I have a straight path of travel like below:

A <----------------------------------------------------------------------------------> B

I have an object denoted by X that travels between these two points. I do not get directional information from the GPS, just coordinates. From this I can calculate the distance to each of the endpoints of the path of travel.

A <-----------X----------------------------------------------------------------------> B

At this point, the object has traveled a given distance from A to B (but we do not know that). We are a distance of 11 units from A, and 129 units from B.

A <------------------------X---------------------------------------------------------> B

Here we have traveled some more distance, and have a new coordinate point. I have a distance of 23 units to A, and 117 units to B.

What I want to do

What I would like to do, is to be able to take the distances [I will have a whole list of distances to each point as a function of time], and create some sort of equation that I can program in that will accept the points and return some number that correlates a change in the distance to point A versus a change in the distance to point B, that would give me a reasonable indicator that I am in fact traveling from point A to point B, and not the other way.

Is this something that can be done? I always got the change formulas mixed up, and given this is for an application I would like to make sure it is done the right way!

If it can be done, what would be the best way to approach it?

1

There are 1 best solutions below

0
On

If you can remember your position in the previous step, say previously, you are at distance $x_{t-1}$ from $A$ and now you are at distance $x_t$ from $A$.

If you are in the right direction, then $x_t-x_{t-1}>0$.