如何从球面上的当前点(经/纬)找到线段上的最近点

时间:2019-04-10 15:09:43

标签: algorithm math geometry geo

例如: 可以说,地球地图上有某种直墙,我们知道其起点和终点的经/纬坐标:

wall.start.lat, wall.start.lon
wall.end.lat, wall.end.lon

此外,我们还有某种对象:

object.lat
object.lon

如果我要从该对象走到该表面上的墙,我需要找到最靠近该对象的墙。

在飞机上解决起来很容易,但是我坚持使用球体。

2 个答案:

答案 0 :(得分:1)

您可以在this latlong page

使用跨轨距离部分
 I’ve sometimes been asked about distance of a point from a great-circle path (sometimes called cross track error).

Formula:    dxt = asin( sin(δ13) ⋅ sin(θ13−θ12) ) ⋅ R
where   δ13 is (angular) distance from start point to third point
θ13 is (initial) bearing from start point to third point
θ12 is (initial) bearing from start point to end point
R is the earth’s radius
JavaScript: 
var δ13 = d13 / R;
var dXt = Math.asin(Math.sin(δ13)*Math.sin(θ13-θ12)) * R;
Here, the great-circle path is identified by a start point and an end point – depending on what initial data you’re working from, you can use the formulas above to obtain the relevant distance and bearings. The sign of dxt tells you which side of the path the third point is on.

The along-track distance, from the start point to the closest point on the path to the third point, is

Formula:    dat = acos( cos(δ13) / cos(δxt) ) ⋅ R
where   δ13 is (angular) distance from start point to third point
δxt is (angular) cross-track distance
R is the earth’s radius
JavaScript: 
var δ13 = d13 / R;
var dAt = Math.acos(Math.cos(δ13)/Math.cos(dXt/R)) * R;

并应用给定目标点的距离和距起始点的方位方法来获取点坐标

答案 1 :(得分:0)

我会

  1. 假设单位球面,计算从中心到线段端点的向量
  2. 叉积以获取包含分段的平面的法线
  3. 用对象点归一化长度和点积以获取其与平面的距离
  4. asin()可以将其转换为沿曲面到段的大圆弧路径的距离
  5. 乘以实际半径即可得到合适的单位

您还需要在目标点和线段端点之间找到距离,以防距离变近。