I have two points, I need the distance between line AB & point C. Along with that I also want the length of AD where D is the projection/intersection point of C on AB. In 2-d I can get the projection point as mention here but ::

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));

But I want to do the same considering the coordinates on a sphere not on a 2-D surface.Thanks in advance! enter image description here

1

There are 1 answers

0
user101 On

very useful link for calculations on spheriacal plane/earth : https://www.movable-type.co.uk/scripts/latlong.html Cross-track distance & Along track distance gives me CD & AD respectively.