我有两点,我需要线 AB 和点 C 之间的距离。除此之外,我还需要 AD 的长度,其中 D 是 AB 上 C 的投影/交点。在二维中,我可以得到这里提到的投影点,但是::
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));
但是考虑到球体上的坐标而不是二维表面上的坐标,我想做同样的事情。提前致谢! 在此处输入图像描述