Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two coordinates(latitude,longitude) which is defining line on the map. The line has direction. Then I have series of other coordinates moving either roughly along this line and towards direction or opposite direction. Also they can cross the line, etc. The important part is that I need to identify only the case when series of points are moving along and towards direction. Those series are coordinates from gps. Let's also define threshold in meters for identifying that point "belongs" to line. This will include gps error and line error.

I am looking for some formula which I could apply to each point, then after applying twice I can identify direction and continue until end of the line. Below is drawing (sorry for finger quality), hopefully demonstrating what I mean.

enter image description here

Green dots are series which are moving towards line direction. They are what we need to identify. Top blue dots are series moving opposite direction. Also want to emphasize that those lines are not really lines and maybe we need to consider their roundness.

share|cite|improve this question
Do I have to start solving this by converting spherical coordinates into Cartesian? – Pablo Nov 5 '12 at 15:21
up vote 0 down vote accepted

A geodesic on a sphere correspond to the intersection of that sphere with a plane through its origin. So instead of talking about a line on a sphere, you could just as well talk about a plane. The plane would be defined by your two defining points together with the origin. You could determine its normal vector by computing the cross product of the two defining points. Normalizing this normal vector leads you to the Hesse normal form of the plane which you can use to compute distance from the line. OK, it will really be distance form the plane, but unless your acceptance range is really large, this will make almost no difference.

To identify the direction traveled between two points, you can computetheir cross product, and then the scalar product of that vector with the normal vector of your plane. The result will be positive if the movement was in the direction of the line, and negative otherwise. If you get all your cross products ordered consistently, that is, otherwise the signs flip.

My use of cross products implies that you're converting from polar coordinates on the sphere to Cartesian coordinates in 3D.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.