點到線的距離大圓功能無法正常工作。 - Distance from Point To Line great circle function not working right. -开发者知识库

點到線的距離大圓功能無法正常工作。 - Distance from Point To Line great circle function not working right. -开发者知识库,第1张

I need to get the distance from a lat/lng point to a line. Of course needs to follow the Great Circle.

我需要從lat / lng點到線的距離。當然需要遵循Great Circle。

I found a great article on this at http://www.movable-type.co.uk/scripts/latlong.html

我在http://www.movable-type.co.uk/scripts/latlong.html找到了一篇很棒的文章

but the code is not working right. Either I am doing something wrong or there is something missing. Here is the function in question. See the link for the other functions if needed.

但代碼不能正常工作。我做錯了什么或者有什么東西丟失了。這是有問題的功能。如果需要,請參閱其他功能的鏈接。

    var R = 3961.3
    LatLon.crossTrack = function(lat1, lon1, lat2, lon2, lat3, lon3) {
     var d13 = LatLon.distHaversine(lat1, lon1, lat3, lon3);
     var brng12 = LatLon.bearing(lat1, lon1, lat2, lon2);
     var brng13 = LatLon.bearing(lat1, lon1, lat3, lon3);
     var dXt = Math.asin(Math.sin(d13/R)*Math.sin(brng13-brng12)) * R;
     return dXt;
    } 

lat/lon1 = -94.127592, 41.81762

lat / lon1 = -94.127592,41.81762

lat/lon2 = -94.087257, 41.848202

lat / lon2 = -94.087257,41.848202

lat/lon3 = -94.046875, 41.791057

lat / lon3 = -94.046875,41.791057

This reports 0.865 miles. The actual distance is 4.29905 miles.

這報告0.865英里。實際距離是4.29905英里。

Any clues as to how to fix this? I am not a mathematician, just a long in the tooth programmer.

關於如何解決這個問題的任何線索?我不是數學家,只是牙齒程序員中的一個長期。

3 个解决方案

#1


Most trig functions need radians. Are your angular measures in degrees? Perhaps they need to be converted using the usual formula:

大多數trig函數需要弧度。你的角度測量是度數嗎?也許他們需要使用通常的公式進行轉換:

2*π radians = 360 degrees

2 *π弧度= 360度

If you look under the formula for Haversine formula, you'll see this:

如果你看看Haversine公式的公式,你會看到:

(Note that angles need to be in radians to pass to trig functions).

(注意角度需要以弧度表示才能傳遞給trig函數)。

最佳答案:

本文经用户投稿或网站收集转载,如有侵权请联系本站。

发表评论

0条回复