【问题标题】:Calculating bearing error计算轴承误差
【发布时间】:2013-08-02 10:33:27
【问题描述】:

这是我使用的公式:

 double lat1 = [self getRadiansFromDegress:self.LocationLatitude];
    double lat2 = [self getRadiansFromDegress:PointOfInterest.latitude];

    double x = sin(lonDiff) * cos(lat2);
    double y = cos(lat1)*sin(lat2) - sin(lat1)*cos(lat2)*cos(longDiff);

    double bearingRad = atan2(x,y);
    double bearingDeg = [self getDegreesFromRadians:bearingRad];
    NSLog(@"Bearing: %f", bearingDeg);

对于 lat1 = 30.61

lat2 = 30.620954

lon1 = -96.342

lon2 = -96.345238

longDiff = -0.003238

根据这个网站:http://www.yourhomenow.com/house/haversine.html 我应该得到大约 345 度,但我的代码返回 -86.028010 度。谁能明白为什么会有如此不同?

【问题讨论】:

    标签: ios objective-c gps bearing


    【解决方案1】:

    在 atan2 中,您交换了 x 和 y。 正确的顺序是y,x:

    更正

    double bearingRad = atan2(y, x);
    

    另见:

    #include <math.h>
    double atan2( double y, double x );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多