给定两个点Ax1,y1和Bx2,y2,我想找到第三点Cx3,y3与线AB之间的距离以及球面上AD的长度

问题描述

我有两个点,我需要线AB和点C之间的距离。与此同时,我还想要AD的长度,其中D是C在AB上的投影/交叉点。在二维中,我可以得到这里提到的投影点,但是::

double A=thirdX-startX;
double B=thirdY-startY;
double C=endX-startX;
double D=endY-startY;
double dot = A * C + B * D;
double len_sq = C * C + D * D;

double xProjection,yProjection,param;
param = dot / len_sq;
if (param < 0) {
    xProjection = startX;
    yProjection = startY;
}
else if (param > 1) {
    xProjection = endX;
    yProjection = endY;
}
else {
    xProjection = startX + param * C;
    yProjection = startY + param * D;
}
double deltaX= thirdX -xProjection;
double deltaY= thirdY-yProjection;
double AD= Math.sqrt(deltaX*deltaX+deltaY*deltaY);
double AD= Math.sqrt((startX-xProjection)*(startX-xProjection)+(startY-yProjection)*(startY-yProjection));

但是考虑到球体的坐标而不是二维表面上的坐标,我想做同样的事情,谢谢! enter image description here

解决方法

关于球面/地球计算的非常有用的链接:https://www.movable-type.co.uk/scripts/latlong.html 跨轨距离和沿轨距离分别给了我CD和AD。