1. <small id='FEvaJ'></small><noframes id='FEvaJ'>

      2. <legend id='FEvaJ'><style id='FEvaJ'><dir id='FEvaJ'><q id='FEvaJ'></q></dir></style></legend>
          <bdo id='FEvaJ'></bdo><ul id='FEvaJ'></ul>
        <i id='FEvaJ'><tr id='FEvaJ'><dt id='FEvaJ'><q id='FEvaJ'><span id='FEvaJ'><b id='FEvaJ'><form id='FEvaJ'><ins id='FEvaJ'></ins><ul id='FEvaJ'></ul><sub id='FEvaJ'></sub></form><legend id='FEvaJ'></legend><bdo id='FEvaJ'><pre id='FEvaJ'><center id='FEvaJ'></center></pre></bdo></b><th id='FEvaJ'></th></span></q></dt></tr></i><div id='FEvaJ'><tfoot id='FEvaJ'></tfoot><dl id='FEvaJ'><fieldset id='FEvaJ'></fieldset></dl></div>

      3. <tfoot id='FEvaJ'></tfoot>
      4. 计算两个位置之间的方位角(纬度、经度)

        时间:2023-09-02

          <small id='TbIOM'></small><noframes id='TbIOM'>

          • <bdo id='TbIOM'></bdo><ul id='TbIOM'></ul>

              <tbody id='TbIOM'></tbody>

            <i id='TbIOM'><tr id='TbIOM'><dt id='TbIOM'><q id='TbIOM'><span id='TbIOM'><b id='TbIOM'><form id='TbIOM'><ins id='TbIOM'></ins><ul id='TbIOM'></ul><sub id='TbIOM'></sub></form><legend id='TbIOM'></legend><bdo id='TbIOM'><pre id='TbIOM'><center id='TbIOM'></center></pre></bdo></b><th id='TbIOM'></th></span></q></dt></tr></i><div id='TbIOM'><tfoot id='TbIOM'></tfoot><dl id='TbIOM'><fieldset id='TbIOM'></fieldset></dl></div>

            <legend id='TbIOM'><style id='TbIOM'><dir id='TbIOM'><q id='TbIOM'></q></dir></style></legend>

                  <tfoot id='TbIOM'></tfoot>
                  本文介绍了计算两个位置之间的方位角(纬度、经度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试开发自己的增强现实引擎.

                  在互联网上搜索,我发现这个有用的还有另一种获取beta的实现方式:

                  - (float)angleFromCoordinate:(CLLocationCoordinate2D)first toCoordinate:(CLLocationCoordinate2D)second {浮动纵向差异 = second.longitude - first.longitude;float latitudinalDifference = second.latitude - first.latitude;浮动可能方位角 = (M_PI * .5f) - atan(latitudinalDifference/longitudinalDifference);if (longitudinalDifference > 0)返回可能的方位角;else if (longitudinalDifference < 0)返回可能的方位角 + M_PI;else if (latitudinalDifference < 0)返回 M_PI;返回 0.0f;}

                  它使用这个公式:

                  float possibleAzimuth = (M_PI * .5f) - atan(latitudinalDifference/longitudinalDifference);

                  为什么 (M_PI * .5f) 在这个公式中?没看懂.

                  继续搜索,我发现另一个页面在谈论如何计算2个位置的距离和方位.在此页面中还有另一个实现:

                  /*** 返回从该点到提供点的(初始)方位角,以度为单位* 见 http://williams.best.vwh.net/avform.htm#Crs** @param {LatLon} 点:目标点的纬度/经度* @returns {Number} 初始方位角(以度数为单位)*/LatLon.prototype.bearingTo = 函数(点){var lat1 = this._lat.toRad(), lat2 = point._lat.toRad();var dLon = (point._lon-this._lon).toRad();var y = Math.sin(dLon) * Math.cos(lat2);var x = Math.cos(lat1)*Math.sin(lat2) -Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);var brng = Math.atan2(y, x);返回 (brng.toDeg()+360) % 360;}

                  哪个是正确的?

                  解决方案

                  计算方位

                  //来源JSONObject 源 = step.getJSONObject("start_location");双 lat1 = Double.parseDouble(source.getString("lat"));双 lng1 = Double.parseDouble(source.getString("lng"));//目的地JSONObject 目的地 = step.getJSONObject("end_location");双 lat2 = Double.parseDouble(destination.getString("lat"));双 lng2 = Double.parseDouble(destination.getString("lng"));双 dLon = (lng2-lng1);双 y = Math.sin(dLon) * Math.cos(lat2);双倍 x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);双 brng = Math.toDegrees((Math.atan2(y, x)));brng = (360 - ((brng + 360) % 360));

                  将度数转换为弧度

                  弧度 = 度数 * PI/180

                  将弧度转换为度数

                  度数 = 弧度 * 180/PI

                  I'm trying to develop my own augmented reality engine.

                  Searching on internet, I've found this useful tutorial. Reading it I see that the important thing is bearing between user location, point location and north.

                  The following picture is from that tutorial.

                  Following it, I wrote an Objective-C method to obtain beta:

                  + (float) calculateBetaFrom:(CLLocationCoordinate2D)user to:(CLLocationCoordinate2D)destination
                  {
                      double beta = 0;
                      double a, b = 0;
                  
                      a = destination.latitude - user.latitude;
                      b = destination.longitude - user.longitude;
                  
                      beta = atan2(a, b) * 180.0 / M_PI;
                      if (beta < 0.0)
                          beta += 360.0;
                      else if (beta > 360.0)
                          beta -= 360;
                  
                      return beta;
                  }
                  

                  But, when I try it, it doesn't work very well.

                  So, I checked iPhone AR Toolkit, to see how it works (I've been working with this toolkit, but it is so big for me).

                  And, in ARGeoCoordinate.m there is another implementation of how to obtain beta:

                  - (float)angleFromCoordinate:(CLLocationCoordinate2D)first toCoordinate:(CLLocationCoordinate2D)second {
                  
                      float longitudinalDifference    = second.longitude - first.longitude;
                      float latitudinalDifference     = second.latitude  - first.latitude;
                      float possibleAzimuth           = (M_PI * .5f) - atan(latitudinalDifference / longitudinalDifference);
                  
                      if (longitudinalDifference > 0) 
                          return possibleAzimuth;
                      else if (longitudinalDifference < 0) 
                          return possibleAzimuth + M_PI;
                      else if (latitudinalDifference < 0) 
                          return M_PI;
                  
                      return 0.0f;
                  }
                  

                  It uses this formula:

                  float possibleAzimuth = (M_PI * .5f) - atan(latitudinalDifference / longitudinalDifference);
                  

                  Why is (M_PI * .5f) in this formula? I don't understand it.

                  And continue searching, I've found another page talking about how to calculate distance and bearing of 2 locations. In this page there is another implementation:

                  /**
                   * Returns the (initial) bearing from this point to the supplied point, in degrees
                   *   see http://williams.best.vwh.net/avform.htm#Crs
                   *
                   * @param   {LatLon} point: Latitude/longitude of destination point
                   * @returns {Number} Initial bearing in degrees from North
                   */
                  LatLon.prototype.bearingTo = function(point) {
                    var lat1 = this._lat.toRad(), lat2 = point._lat.toRad();
                    var dLon = (point._lon-this._lon).toRad();
                  
                    var y = Math.sin(dLon) * Math.cos(lat2);
                    var x = Math.cos(lat1)*Math.sin(lat2) -
                            Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
                    var brng = Math.atan2(y, x);
                  
                    return (brng.toDeg()+360) % 360;
                  }
                  

                  Which one is the right one?

                  解决方案

                  Calculate bearing

                  //Source
                  JSONObject source = step.getJSONObject("start_location");
                  double lat1 = Double.parseDouble(source.getString("lat"));
                  double lng1 = Double.parseDouble(source.getString("lng"));
                  
                  // destination
                  JSONObject destination = step.getJSONObject("end_location");
                  double lat2 = Double.parseDouble(destination.getString("lat"));
                  double lng2 = Double.parseDouble(destination.getString("lng"));
                  
                  double dLon = (lng2-lng1);
                  double y = Math.sin(dLon) * Math.cos(lat2);
                  double x = Math.cos(lat1)*Math.sin(lat2) - Math.sin(lat1)*Math.cos(lat2)*Math.cos(dLon);
                  double brng = Math.toDegrees((Math.atan2(y, x)));
                  brng = (360 - ((brng + 360) % 360));
                  

                  Convert Degrees into Radians

                  Radians = Degrees * PI / 180
                  

                  Convert Radians into Degrees

                  Degrees = Radians * 180 / PI
                  

                  这篇关于计算两个位置之间的方位角(纬度、经度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Android 中同时使用 GPS 和 Network Provider 下一篇:使用纬度和经度获取特定地址

                  相关文章

                  最新文章

                      <small id='Qh7IR'></small><noframes id='Qh7IR'>

                      <i id='Qh7IR'><tr id='Qh7IR'><dt id='Qh7IR'><q id='Qh7IR'><span id='Qh7IR'><b id='Qh7IR'><form id='Qh7IR'><ins id='Qh7IR'></ins><ul id='Qh7IR'></ul><sub id='Qh7IR'></sub></form><legend id='Qh7IR'></legend><bdo id='Qh7IR'><pre id='Qh7IR'><center id='Qh7IR'></center></pre></bdo></b><th id='Qh7IR'></th></span></q></dt></tr></i><div id='Qh7IR'><tfoot id='Qh7IR'></tfoot><dl id='Qh7IR'><fieldset id='Qh7IR'></fieldset></dl></div>

                      <tfoot id='Qh7IR'></tfoot>
                      • <bdo id='Qh7IR'></bdo><ul id='Qh7IR'></ul>
                    1. <legend id='Qh7IR'><style id='Qh7IR'><dir id='Qh7IR'><q id='Qh7IR'></q></dir></style></legend>