通过两个 long/lat 点的中间画一条垂直线

Draw a perpendicular line through middle of two long/lat points

您好,我目前正在尝试通过两条 long/lat 线画一条线来创建一个三角形。到目前为止,我已经设法画了一条线,但这条线并不垂直,而且看起来是歪斜的。这是我的代码:

    startPosition = [-0.17640, 51.426700];
    endPosition =  [0.17640, 51.796700];

    triangleSizeY = (endPosition [1] - startPosition[1]) / 6;
    /*subtract 
    end from start to work out direction and also use this divided by 6 to 
    get distance*/
    triangleSize *= -1;

    triangleSizeX = (endPosition [0] - startPosition[0]) / 6;
    /*subtract 
    end from start to work out direction and also use this divided by 6 to 
    get distance*/
    triangleSize *= -1;

    var cx = (startPosition[0] + endPosition[0]) / 2;
    var cy = (startPosition[1] + endPosition[1]) / 2;
    var dx = (endPosition[0] - startPosition[0]) / 2;
    var dy = (endPosition[1] - startPosition[1]) / 2;
    positions[0] = [midPoint[0] + triangleSizeX, midPoint[1] + 
    triangleSizeY];
    positions[1] = [cx - dy, cy + dx];
    positions[2] = [cx + dy, cy - dx];

这是它的样子:

首先,lat/lon 是 angular,因此您不能使用线性类型的距离。解决此问题需要采取的步骤:

  1. 计算您想要垂直线的 2 lat/lon 对之间的距离。
  2. 取上述步骤计算出的距离的一半,得到中点范围。
  3. 计算 2 lat/lon 对之间的方位。 (参见下面关于从 2 lat/lon 计算方位的参考资料)
  4. 有了一半的距离和方位,你可以计算出中点的lat/lon。这称为根据范围和方位计算 lat/lon。 (请参阅下面的参考资料。)
  5. 现在您可以从第 3 步中的方位角 adding/subtracting 90 度垂直于中点。确定要从 range/bearing 计算新 lat/lon 的范围就像在第 4 步中一样。

此站点 (https://www.movable-type.co.uk/scripts/latlong.html) 具有执行此操作所需的计算。另外,由于距离比较小,可以用Equirectangular近似于Haversine来计算距离。