[GIS] How to find a point on given line that its distance from another point is given also

algorithmdistance

I have this input:

  1. (lat1,lon1), (lat2,lon2) – Two coordinates that create the line
  2. (lat0, lat0) – Point on this line
  3. d – distance

I want to find a point (lat, lon), where

  1. (lat, lon) is on the line (mentioned above)
  2. The distance between (lat, lon) and (lat0, lon0) is d

The direction of (lat0, lon0)-to-(lat, lon) is not importent right now.
[and of course, the lat/lon is given as geographic coordinates in degrees].

Can anyone knows any algorithm for that?

Many thanks!

Best Answer

The input is redundant, so let's focus on the essentials:

  1. You have a "base point" p0 with coordinates (x0,z0) (latitude and longitude in degrees).

  2. You have a "target point" p1 with coordinates (x1,z1).

  3. The distance to travel from p towards p1 is d. Let (x,z) be the coordinates of the endpoint p: we wish to compute x and z.

Because (a) d is a few meters, (b) p and p1 are not near the poles, and (c) high accuracy is not needed, we can use Euclidean calculations upon applying a moderately accurate projection. About the simplest is the cylindrical projection

(x,z) --> (x, z * Cos(x)) = (x, y).

This reflects the shrinking of longitude (z) with varying latitude (x).

From now on we may compute with our points as if they were vectors. The solution is obtained in simple steps:

(i) The direction vector from p0 to p1 is p1 - p2 with coordinates v = (x1-x0, y1-y0).

(ii) The length of this vector, by the Pythagorean Theorem, is the square root of the sum of squares of its coordinates, Sqrt((x1-x0)^2 + (y1-y0)^2). Call this 'a'.

(iii) A parallel vector of length d is obtained by scaling the direction vector v by d/a, after expressing d in degrees. To do this, divide d by 111300 (meters per degree). Then rescale by multiplying each of x1-x0 and y1-y0 by d/a. Call this vector 'w'.

(iv) Displacing p0 by w is obtained by adding the vectors: p = p0 + w = (x,y).

(v) Unproject (x,y). This gives (x,z) = (x, y/Cos(x)).

Example