如何在 ColdFusion 中计算半正矢公式
我在 CF 中找不到半正矢公式(根据球体上两点的经度和纬度计算出两点之间距离的公式)的任何示例。
Wikipeda 有其他语言的示例 (http://en.wikipedia.org/wiki/Haversine_formula),但没有 CF 的示例。
下面是另一位开发人员对 CF 的解释,是内部的,尚未经过充分测试。我有兴趣看看其他人在 CF 中是如何计算的。我也有兴趣了解以下示例的意见,以了解如何简化它。
var variables.intEarthRadius = 6371; // in km
var local.decRadius = arguments.radius / 1000; // convert radius given in metres to kilometres
var local.latMax = arguments.latitude + degree(local.decRadius / variables.intEarthRadius);
var local.latMin = arguments.latitude - degree(local.decRadius / variables.intEarthRadius);
var local.lngMax = arguments.longitude + degree(local.decRadius / variables.intEarthRadius / cos(radian(arguments.latitude)));
var local.lngMin = arguments.longitude - degree(local.decRadius / variables.intEarthRadius / cos(radian(arguments.latitude)));
private numeric function degree(required numeric radian) hint="I convert radians to degrees." {
return arguments.radian * 180 / pi();
}
private numeric function radian(required numeric degrees) hint="I convert degrees to radians." {
return arguments.degrees * pi() / 180;
}
I cannot find any examples in CF of the Haversine formula (a formula for working out distances between two points on a sphere from their longitudes and latitudes).
Wikipeda has examples in other languages (http://en.wikipedia.org/wiki/Haversine_formula) but none in CF.
An interpretation in CF is below by another developer, internal, and not fully tested. I am interested to see how others have calculated this in CF. I would also be interested to get opinions on the example below to how it can be simplified.
var variables.intEarthRadius = 6371; // in km
var local.decRadius = arguments.radius / 1000; // convert radius given in metres to kilometres
var local.latMax = arguments.latitude + degree(local.decRadius / variables.intEarthRadius);
var local.latMin = arguments.latitude - degree(local.decRadius / variables.intEarthRadius);
var local.lngMax = arguments.longitude + degree(local.decRadius / variables.intEarthRadius / cos(radian(arguments.latitude)));
var local.lngMin = arguments.longitude - degree(local.decRadius / variables.intEarthRadius / cos(radian(arguments.latitude)));
private numeric function degree(required numeric radian) hint="I convert radians to degrees." {
return arguments.radian * 180 / pi();
}
private numeric function radian(required numeric degrees) hint="I convert degrees to radians." {
return arguments.degrees * pi() / 180;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你看过这个吗...
http://cflib.org/udf/getHaversineDistance
(自 CFLib.org 切换到静态站点生成器以来的新 URL)
Have you looked at this...
http://cflib.org/udf/getHaversineDistance
(New URL since CFLib.org switched to static site generator)