cn1 中的数学 class 函数

Math class functionality in cn1

我正在尝试计算非常短距离的 2 个 GPS 坐标之间的距离。我找到了一些方法,但它们都需要数学方法 class。我的目标是实现这样的算法:

     public static double haversine(
        double lat1, double lng1, double lat2, double lng2) {
    int r = 6371; // average radius of the earth in km
    double dLat = Math.toRadians(lat2 - lat1);
    double dLon = Math.toRadians(lng2 - lng1);
    double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
       Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) 
      * Math.sin(dLon / 2) * Math.sin(dLon / 2);
    double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    double d = r * c;
    return d;
}

我知道如何在度数和弧度之间进行转换。有没有办法在 cn1 中计算这个,或者有没有办法使用比 MathUtil 提供的更多的数学函数,例如 sin cos 和 tan 函数。

MapComponent 中有一个静态实用程序方法可以做到这一点:

public static long distance(double latitude1, double longitude1, double latitude2, double longitude2) {
    double latitudeSin = Math.sin(Math.toRadians(latitude2 - latitude1) / 2);
    double longitudeSin = Math.sin(Math.toRadians(longitude2 - longitude1) / 2);
    double a = latitudeSin * latitudeSin
            + Math.cos(Math.toRadians(latitude1)) * Math.cos(Math.toRadians(latitude2)) * longitudeSin * longitudeSin;
    double c = 2 * MathUtil.atan2(Math.sqrt(a), Math.sqrt(1 - a));
    return (long) (6378137 * c);
}