4
votes

I want to calculate the distance from a point given by latitude and longitude to a line-segment given by two points (part of a great-circle). All coordinates are given in WGS84.

enter image description here

I know how to calculate this in Cartesian coordinates but not on a sphere. Can somebody please provide the formula?

2
i think you might have more luck with this on mathematics.stackexchangeTimothy Groote
I'm voting to close this question as off-topic because it is about Mathematics instead of programming or software development.Pang
Should the distance d be a straight line cutting through the sphere, or should it also be a great-circle segment?hypehuman
@hypehuman: It should also be a great-circle-segment.user2033412

2 Answers

3
votes

This is cross-track distance described here

dxt = asin( sin(δ13) ⋅ sin(θ13−θ12) ) ⋅ R
    where
 δ13 is (angular) distance from start point to third point
     θ13 is (initial) bearing from start point to third point
     θ12 is (initial) bearing from start point to end point
     R is the earth’s radius

You can calculate needed distance and bearings using formulas from given page

distance
a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
c = 2 ⋅ atan2( √a, √(1−a) )
d = R ⋅ c
where   
 φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km);

bearing
θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )
    where
φ1,λ1 is the start point, φ2,λ2 the end point (Δλ is the difference in longitude)

note that angles need to be in radians to pass to trig functions

2
votes
  1. spherical to 2D Cartesian

    if the distance is not too far and not around pole singularities you can convert both line segment and line emitting from your point and perpendicular to your segment to spherical coordinates (if they are not already) and use the 2 angles as Cartesian space (ignoring radius).

    1. compute intersection point

    2. convert back to spherical

    3. compute arclength between point and intersection

      hard to say if you're using sphere or WGS84 or what ....

  2. Cartesian 3D

    lets have arc segment AB, sphere of radius R and center C (ideally (0,0,0)) and point P then I see it like this:

    3D cartesian

    1. find intersection point P' between plane ABC and its normal going through point P in 3D Cartesian

    2. project it back on sphere surface

      For spherical surface is this easy as the projection means just to change the vector P'C length to R (if the sphere is centered around (0,0,0)).

      P'' = (R*(P'-C)/|P'-C|) + C
      
    3. compute arclength between the 2 points |P-P''|

      Also simple for spherical surface just compute the angle between vectors P-C and P''-C

      ang = acos(dot(P-C,P''-C)/(R*R)); // [radians]
      

      and convert to arclength

      d = ang*R; // [same Units as R]