Minimum distance between a point and a line in latitude, longitude

后端 未结 5 1951
感情败类
感情败类 2020-12-28 09:45

I have a line with two points in latitude and longitude
A: 3.222895, 101.719751
B: 3.227511, 101.724318

and 1 point
C: 3.224972, 101.722932

Ho

5条回答
  •  执念已碎
    2020-12-28 10:05

    See post here: https://stackoverflow.com/a/33343505/4083623

    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;
    

提交回复
热议问题