【发布时间】:2018-09-25 03:10:37
【问题描述】:
我想计算 2 个 GPS 位置之间的方位,我对我的算法提出了 this page 建议:
public static double Bearing(IPointGps pt1, IPointGps pt2)
{
double x = Math.Cos(pt1.Latitude) * Math.Sin(pt2.Latitude) - Math.Sin(pt1.Latitude) * Math.Cos(pt2.Latitude) * Math.Cos(pt2.Longitude - pt1.Longitude);
double y = Math.Sin(pt2.Longitude - pt1.Longitude) * Math.Cos(pt2.Latitude);
// Math.Atan2 can return negative value, 0 <= output value < 2*PI expected
return (Math.Atan2(y, x) + Math.PI * 2)%(Math.PI * 2);
}
然后我使用这种方法以度为单位转换我的值
public static double RadiansToDegrees(double angle)
{
return (angle * 180.0) / Math.PI;
}
我有以下测试样本:
- Point1(纬度、经度)= 43.6373638888888888888888888888889, 1.35762222222222222222222222222222
- Point2(纬度、经度)= 43.6156444444444444444444444444444,1.380225
- 预期方位角 = 323°
但是,我获得了 315.5° (5.5062235835910762 rad) 的方位角。如果我计算预期的弧度值,我会得到 5.637413,这毫无疑问是我的问题在于我的方位方法。
我已经使用 .Net Math 包(包括 Cos、Sin、Tan 和 ATan 方法)实现了其他计算方法,并且我的单元测试以 1e-12 精度通过。我错过了什么?
PS:我还尝试重新实现 Atan2 方法,以防它缺乏精度。我得到了完全相同的结果
编辑:我的纬度和经度按照以下界面加倍
public interface IPointGps
{
double Latitude { get; }
double Longitude { get; }
}
【问题讨论】: