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

后端 未结 5 1944
感情败类
感情败类 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:15

    Calculate bearing for each: C to A , and C to B:

    var y = Math.sin(dLon) * Math.cos(lat2);
    var x = Math.cos(lat1)*Math.sin(lat2) -
            Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
    var brng = Math.atan2(y, x).toDeg();
    

    dLon= lon2-lon1;

    Calculate cross-track distance:

    var dXt = Math.asin(Math.sin(distance_CB/R)*Math.sin(bearing_CA-bearing_CB)) * R;
    

    R is the radius of earth, dXt is the minimum distance you wanted to calculate.

提交回复
热议问题