点到线大圆弧功能的距离不正确. [英] Distance from Point To Line great circle function not working right.
问题描述
我需要获取从经度/纬度点到直线的距离.当然需要跟随大圈子.
I need to get the distance from a lat/lng point to a line. Of course needs to follow the Great Circle.
我在 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
这报告0.865英里.实际距离是4.29905英里.
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.
推荐答案
大多数三角函数需要弧度.您的角度量度是多少度?也许需要使用通常的公式进行转换:
Most trig functions need radians. Are your angular measures in degrees? Perhaps they need to be converted using the usual formula:
2 *π弧度= 360度
2*π radians = 360 degrees
如果您在Haversine公式的公式下查看,则会看到以下内容:
If you look under the formula for Haversine formula, you'll see this:
(请注意,角度必须以弧度为单位才能传递给三角函数).
(Note that angles need to be in radians to pass to trig functions).
这篇关于点到线大圆弧功能的距离不正确.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!