使用航空公式(给定径向和距离的Lat / lon);经度不归

时间:2016-02-19 03:19:53

标签: javascript latitude-longitude

这是计算给定径向和距离的纬度/经度的公式,可在此处找到:http://williams.best.vwh.net/avform.htm#LL

lat=asin(sin(lat1)*cos(d)+cos(lat1)*sin(d)*cos(tc))
 IF (cos(lat)=0)
    lon=lon1      // endpoint a pole
 ELSE
    lon=mod(lon1-asin(sin(tc)*sin(d)/cos(lat))+pi,2*pi)-pi
 ENDIF

以下是我目前使用的代码(以弧度计算的所有输入和输出):

nx = Math.asin(Math.sin(lat0) * Math.cos(d) + Math.cos(lat0) * Math.sin(d) * Math.cos(c));

ny = mod(lon0 - Math.asin(sin(c) * Math.sin(d) / Math.cos(lat1)) + Math.PI, 2 * Math.PI) - Math.PI;

return [nx, ny];

}

nx打印没有问题,但是ny不打印。

1 个答案:

答案 0 :(得分:0)

如果mod是模数运算符

变化:

ny = mod(lon0 - Math.asin(sin(c) * Math.sin(d) / Math.cos(lat1)) + Math.PI, 2 * Math.PI) - Math.PI;

// ....................vvvvv note, I spotted this omission as well
ny =((lon0 - Math.asin(Math.sin(c) * Math.sin(d) / Math.cos(lat1)) + Math.PI) % (2 * Math.PI)) - Math.PI;

或创建一个功能

function mod(a, b) {
    return a % b;
}

但是,你需要解决缺少数学的问题。上述