Search code examples
geometrygpscoordinatesprojection

Projection of a GPS point on a segment representing a trajectory


Consider the A-B segment in the picture below; each extremity is a GPS point defined by latitude & longitude (the segment is actually an arc, as it lies on the earth surface).

Point C is not part of the segment. I would like to compute latitude and longitude for point P, i.e. the projection of point C on the A-B segment.

Is there a way to do that without moving to a local cartesian system (e.g. Lat/Long/Alt -> North/East/Down) and back? I would like to avoid it as the points are actually part of long routes spanning many kilometers, and a local cartesian system would not cover the full extent.

<code>intersection</code>


Solution

  • It is possible to find P point using combination of formulas from latlong page.

    At first find δ12 and δ13 - angular distances from start point to end and third point (Distance section)

    Then bearings θ13 and θ12 from start point to the third point and end point (Bearing section)

    Get cross-track angular distance

     δxt = asin( sin(δ13) ⋅ sin(θ13−θ12) )
    

    Use it to get along-track angular distance

      δat = acos( cos(δ13) / cos(δxt) )
    

    and calculate intermediate point P

    a = sin(δ12 - δat) / sin δ12
    b = sin(δat) / sin δ12
    x = a ⋅ cos φ1 ⋅ cos λ1 + b ⋅ cos φ2 ⋅ cos λ2
    y = a ⋅ cos φ1 ⋅ sin λ1 + b ⋅ cos φ2 ⋅ sin λ2
    z = a ⋅ sin φ1 + b ⋅ sin φ2
    
    φi = atan2(z, √x² + y²)
    λi = atan2(y, x)