从点到线的距离大圆函数无法正常工作。
我需要获取从纬度/经度点到直线的距离。 当然需要遵循大圆。
我在 http://www.movable-type 找到了一篇关于此的很棒的文章。 co.uk/scripts/latlong.html
但代码无法正常工作。 要么是我做错了什么,要么是缺少什么。 这是有问题的函数。 如果需要,请参阅其他功能的链接。
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/lon2 = -94.087257, 41.848202
lat/lon3 = -94.046875, 41.791057
此报告 0.865 英里。 实际距离为 4.29905 英里。
有关如何解决此问题的任何线索? 我不是数学家,只是一个老了的程序员。
I need to get the distance from a lat/lng point to a line. Of course needs to follow the Great Circle.
I found a great article on this at 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/lon2 = -94.087257, 41.848202
lat/lon3 = -94.046875, 41.791057
This reports 0.865 miles. The actual distance is 4.29905 miles.
Any clues as to how to fix this? I am not a mathematician, just a long in the tooth programmer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
大多数三角函数需要弧度。 你的角度测量单位是度吗? 也许它们需要使用通常的公式进行转换:
如果您查看半正弦公式,您会看到以下内容:
Most trig functions need radians. Are your angular measures in degrees? Perhaps they need to be converted using the usual formula:
If you look under the formula for Haversine formula, you'll see this:
您的函数是否为这些坐标返回相同的值:
我认为应该,但我的没有。 第三点始终位于赤道以北 0.1 处。 只有经度变化不会影响结果。 看起来确实如此。
Is your function returning same value for these coordinates:
I think it should but mine does not. The 3rd point is always 0.1 to the north from equator. only the longitude changes which should not affect the result. As it seems it does.
我尝试了这个 pointlineddistancetest 发送 aalalatlon 等
I tried this pointlinedistancetest sending it aalatlon etc