我搜索了一下,但找不到完整的答案。在C#中,如果可能的话。我需要一个WGS点和一个WGS点定义的球体线段之间的最短距离(地球精确)。
float DistanceInKilometres(PointF LineStartA, PointF LineEndB, PointF ThePoint)编辑:也许一个插图会有帮助。

请注意,这是一个理想的例子。“点”可以在球体表面的任何地方,也可以是段开始-结束.很明显,我不是在寻找穿过球体的距离。数学不是我更强的一面,所以我不理解正常化或笛卡尔。也许我也应该注意到,路径AB是最短的,距离也是最短的。
发布于 2012-04-19 16:46:53
你可以使用余弦的球面定律:
你必须用地球的半径来计算:
EARTH_RADIUS_KM = 6371;
这里,根据我对OsmMercator.java的贡献,来自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);
}你所要做的就是用点积找到最近的点,然后用距离方程。
下面是最近的例子:
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;
}请记住,这些单位还没有明确宣布。在处理空间中的点时,有多种确定位置的方法。最重要的是,你必须把你的单位确定为一个一致的类型。
当我在地球上的位置工作时,我主要使用lat/长坐标和矢量来表示大小/方向。有几种已知的类型可用于矢量和地球的位置。其中包括:
以你为例,我可能会考虑坚持大地测量。
现在,把这些放在一起,您可能有一些伪代码,如下所示:
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);
}发布于 2012-04-06 19:30:05
如果您的点位于由线段的端点定义的走廊内,并且垂直于这条线,那么这个answer应该可以。
如果你的点位于走廊外,然后计算出从你的点到线段两端的距离,然后取较小的距离。
https://stackoverflow.com/questions/10045544
复制相似问题