How to calculate distance from a point to a line segment, on a sphere?

后端 未结 7 1489
一向
一向 2020-11-27 04:47

I have a line segment (great circle part) on earth. The line segment is defined by the coordinates of its ends. Obviously, two points define two line segments, so assume I a

7条回答
  •  天涯浪人
    2020-11-27 05:12

    For distance up to a few thousands meters I would simplify the issue from sphere to plane. Then, the issue is pretty simply as a easy triangle calculation can be used:

    We have points A and B and look for a distance X to line AB. Then:

    Location a;
    Location b;
    Location x;
    
    double ax = a.distanceTo(x);
    double alfa = (Math.abs(a.bearingTo(b) - a.bearingTo(x))) / 180
                * Math.PI;
    double distance = Math.sin(alfa) * ax;
    

提交回复
热议问题