- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我进行了搜索,但找不到完整的答案。如果可能的话,在 C# 中。我需要 WGS 点和球体上 WGS 点定义的线段之间的最短距离(正好是地球)。
float DistanceInKilometres(PointF LineStartA, PointF LineEndB, PointF ThePoint)
编辑:也许插图会有所帮助
请注意,这是一个理想的例子。 “点”可以是球体表面的任何地方,也可以是线段的起点和终点。显然,我不是在寻找通过球体的距离。数学不是我的强项,所以我不了解归一化 或笛卡尔。也许我还应该注意到路径 AB 是最短的可能路径,而 Distance? 也是最短的可能路径。
最佳答案
您可以使用余弦的球面定律:
您将不得不使用地球的半径进行计算:
EARTH_RADIUS_KM = 6371;
这里,来 self 对 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;
}
请记住,单位尚未明确声明。在处理空间中的点时,有多种方法可以确定位置。最主要的是你必须将你的单位确定为一致的类型。
在处理地球上的位置时,我主要使用纬度/经度坐标和矢量来确定大小/方向。有几种已知类型可用于矢量和地球位置。其中包括:
对于您的示例,我可能会考虑坚持使用 Geodetic。
现在,将这些放在一起,您可能会得到一些如下所示的伪代码:
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);
}
关于c# - wgs 点与 wgs 定义线段的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10045544/
我正在研究 GSHHS 数据库的栅格化,基本上将海岸线多边形和河流线转换为栅格。 http://www.soest.hawaii.edu/pwessel/gshhg/ 河流和海岸数据库是两个不同的文件
我进行了搜索,但找不到完整的答案。如果可能的话,在 C# 中。我需要 WGS 点和球体上 WGS 点定义的线段之间的最短距离(正好是地球)。 float DistanceInKilometres(Po
对于我的应用程序,我需要用于在 LatLon (WGS84) 和 MGRS 之间进行转换的紧凑代码。 JCoord.jar:看起来不错,但 1.1 版本的 jar 大小为 0.5Mb。这是我的应用程序
我目前有一个使用 EPSG:900913 投影的 postgis 数据库,如何将其转换为 WGS 84,我相信这是 Google map 和 OSM 使用的格式。 数据库是用osm2pgsql制作的,
嗨我在弄清楚如何在坐标类型之间进行转换时遇到了一些麻烦。我有一个坐标集列表,描述如下 "坐标始终在WGS84系统中。所有坐标都表示为整数值 x 和 y,其中坐标值乘以 1,000,000。” 一个例子
我正在尝试将地理坐标系转换为 Esri Webmercator,但是当我进行转换时,生成的 x 和 y 的值为 0000003232112222… 和 00000012665321…。这很奇怪,因为坐
我是一名优秀的程序员,十分优秀!