wgs​​点到wgs定义的线段的距离 [英] Distance of wgs point from a wgs defined line segment

查看:120
本文介绍了wgs​​点到wgs定义的线段的距离的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我进行了搜索,但找不到完整的答案. 如果有可能,请使用C#. 我需要球体上​​WGS点和WGS点定义的线段之间的最短距离(精确到地球).

I searched but I could not find a complete answer. In C# if at all possible. I need the shortest distance between a WGS point and a WGS point defined line segment on a sphere (Earth exactly).

float DistanceInKilometres(PointF LineStartA, PointF LineEndB, PointF ThePoint)

也许插图会有所帮助

请注意,这是一个理想的示例. 点"也可以位于球体表面的任何位置,也可以是线段的起点到终点.显然,我不是在寻找通过球体的距离.数学不是我的强项,所以我不理解 normalize 笛卡尔.也许我还应该注意,路径AB是可能的最短路径,而距离?也是可能的最短路径.

Please note that this is an ideal example. 'The point' could be anywhere on the surface of the sphere, the segment start-end, too. Obviously, I'm not looking for the distance through the sphere. Math isn't my stronger side, so I don't understand normalize or to cartesian. Maybe I should also note that path AB, is the shortest possible, and Distance?, is the shortest possible too.

推荐答案

您可以使用余弦的球形定律:

You can use the spherical law of cosines:

  • http://en.wikipedia.org/wiki/Spherical_law_of_cosines
  • http://mathworld.wolfram.com/SphericalSegment.html
  • http://mathworld.wolfram.com/SphericalTrigonometry.html

您将不得不使用地球的半径进行计算:

You will have to use the earth's radius for calculations:

EARTH_RADIUS_KM = 6371;

EARTH_RADIUS_KM = 6371;

在这里,根据我对OsmMercator.java的贡献,来自openstreetmap.org:

Here, from my contributions to OsmMercator.java, from openstreetmap.org:

/**
 * Gets the distance using Spherical law of cosines.
 *
 * @param la1 the Latitude in degrees
 * @param lo1 the Longitude in degrees
 * @param la2 the Latitude from 2nd coordinate in degrees
 * @param lo2 the Longitude from 2nd coordinate in degrees
 * @return the distance
 */
public static double getDistance(double la1, double lo1, double la2, double lo2) {
    double aStartLat = Math.toRadians(la1);
    double aStartLong = Math.toRadians(lo1);
    double aEndLat =Math.toRadians(la2);
    double aEndLong = Math.toRadians(lo2);

    double distance = Math.acos(Math.sin(aStartLat) * Math.sin(aEndLat)
            + Math.cos(aStartLat) * Math.cos(aEndLat)
            * Math.cos(aEndLong - aStartLong));

    return (EARTH_RADIUS_KM * distance);
}

您需要做的就是找到具有点积的最近点,并将其与距离方程式一起使用.

All you need to do is find the closest point with dot product and use that with the distance equation.

这是最接近的例子:

double[] nearestPointSegment (double[] a, double[] b, double[] c)
{
   double[] t= nearestPointGreatCircle(a,b,c);
   if (onSegment(a,b,t))
     return t;
   return (distance(a,c) < distance(b,c)) ? a : c;
}

  • 如何计算球体上从点到线段的距离?
  • http://en.wikipedia.org/wiki/Great-circle_distance
    • How to calculate distance from a point to a line segment, on a sphere?
    • http://en.wikipedia.org/wiki/Great-circle_distance
    • 请记住,尚未明确声明单位.处理空间中的点时,有多种方法可以确定位置.最主要的是您必须将单元固定为一致的类型.

      Keep in mind the units haven't been explicitly declared. When dealing with points in space there're are a variety of ways to determine position. The main thing is you have to nail down your units to a consistent type.

      在地球上定位时,我主要使用纬度/经度坐标和矢量作为幅度/方向.有几种已知的类型可用于矢量和地球的位置.其中包括:

      When working with position on the earth, I mainly use lat/long coordinates and vectors for magnitude/direction. There're are several known types to use for vectors and earth's position. Among them are the following:

      • 以地球为中心的地球固定(ECEF)坐标系
      • 东北-东北(NED)
      • 大地坐标系

      以您的示例为例,我可能会考虑坚持使用大地测量.

      For your example, I might consider sticking to Geodetic.

      现在,将它们放在一起,您可能会有一些伪代码,如下所示:

      Now, bringing this together, you might have some pseudo code which looks like this:

      Where a Vector is made up of Geodetic coordinates:
      class Vector {
       double x=0.0; //latitude
       double y=0.0; //longitude
       double h=0.0; //height
      ...
      }
      
      public Vector closestPoint(Vector lineStartA, Vector lineEndB, final Vector thePoint ) {
          Vector w = thePoint.subtract(lineStartA);
          double proj = w.dot(lineEndB);
          // endpoint 0 is closest point
          if ( proj <= 0.0f )
              return lineStartA;
          else
          {
              //Vector square 
              double vsq = lineEndB.dot(lineEndB);
              // endpoint 1 is closest point
              if ( proj >= vsq )
                  return lineStartA.add(lineEndB);
              else
                  return lineStartA.add(lineEndB.multiply(proj/vsq));
          }
      }      
      
      double DistanceInKilometres(Vector lineStartA, Vector lineEndB, Vector thePoint) {
        Vector cp=closestPoint(lineStartA, lineEndB, thePoint);
        return getDistance(cp.x, cp.y, thePoint.x, thePoint.y);
      }
      

      这篇关于wgs​​点到wgs定义的线段的距离的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆