【问题标题】:How to calculate the Haversine formula in CLIPS如何在 CLIPS 中计算 Haversine 公式
【发布时间】:2019-09-07 04:41:06
【问题描述】:

我正在尝试使用latitudelongitude 计算与城市之间的距离。出于这个原因,我尝试在 CLIPS 中使用半正弦公式,但我无法计算 arctan2(2 参数反正切)。有没有办法解决这个问题?

这是我要重现的代码:

Number.prototype.toRad = function() {
   return this * Math.PI / 180;
}

var lat2 = 42.741; 
var lon2 = -71.3161; 
var lat1 = 42.806911; 
var lon1 = -71.290611; 

var R = 6371; // km 
//has a problem with the .toRad() method below.
var x1 = lat2-lat1;
var dLat = x1.toRad();  
var x2 = lon2-lon1;
var dLon = x2.toRad();  
var a = Math.sin(dLat/2) * Math.sin(dLat/2) + 
                Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
                Math.sin(dLon/2) * Math.sin(dLon/2);  
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
var d = R * c; 

alert(d);

【问题讨论】:

    标签: clips


    【解决方案1】:

    您可以根据 atan 定义实现 atan2 的 deffunction。

    【讨论】:

    • 好的,谢谢,我想知道我是否缺少其他解决方案,但是是的,这可以解决问题!
    • 另一种解决方案是创建一个用户定义的函数,如高级编程指南中所述,然后重新编译 CLIPS。在 CLIPS 源文件 emathfun.c 中有一堆示例,用于现有函数,例如 cos、sin、tan 等。最初的数学函数集是在 1980 年代后期写回的,所以这个可能被忽略或不是一部分那时的 C 标准。
    猜你喜欢
    • 1970-01-01
    • 2017-03-05
    • 2016-11-09
    • 2016-04-03
    • 2023-03-06
    • 1970-01-01
    • 1970-01-01
    • 2011-09-12
    • 2013-01-11
    相关资源
    最近更新 更多