0

I am working on a problem related to finding latitudes and longitudes between two latitudes and longitudes at various distances between them. I got a code from Stackoverflow, which can find the midpoint.

I know, some modification in the stackoverflow code midpoint between two latitude and longitude can solve my problem i,e,finding lat3 and lon3 at a distance 1/4 from lat1,lon1 and 3/4 from lat2,lon2 but i am not able to make that change.Please help.

public static void midPoint(double lat1,double lon1,double lat2,double lon2){

    double dLon = Math.toRadians(lon2 - lon1);

    //convert to radians
    lat1 = Math.toRadians(lat1);
    lat2 = Math.toRadians(lat2);
    lon1 = Math.toRadians(lon1);

    double Bx = Math.cos(lat2) * Math.cos(dLon);
    double By = Math.cos(lat2) * Math.sin(dLon);
    double lat3 = Math.atan2(Math.sin(lat1) + Math.sin(lat2), Math.sqrt((Math.cos(lat1) + Bx) * (Math.cos(lat1) + Bx) + By * By));
    double lon3 = lon1 + Math.atan2(By, Math.cos(lat1) + Bx);

    //print out in degrees
    System.out.println(Math.toDegrees(lat3) + " " + Math.toDegrees(lon3));
}
Manu
  • 177
  • 9
  • 1
    I don't see a clear problem statement here. – Tim Biegeleisen Jan 21 '19 at 21:15
  • Is the problem clear or should i try and explain the problem further. – Manu Jan 21 '19 at 21:24
  • Are you saying, for example, that you have the lat/lon of New York and the lat/lon of London and you want to calculate the lat/lon of the point 3/4 of the way from New York to London? (Places used only for example). And are you referring to great circle distances? – Jason Jan 21 '19 at 21:27
  • As described here (https://en.wikipedia.org/wiki/Great-circle_distance) if your two points are on opposite sides on the planet, then there are infinite number of points that are 3/4 of the way between them on a great circle. – Jason Jan 21 '19 at 21:31
  • Yes Jason, i exactly want the above program to be modified as you have interpreted. But this thing need to be done for latitudes and longitudes which are very close(say,100 meters apart). – Manu Jan 21 '19 at 21:37
  • 1
    If you know how to calculate the midpoint lat/lon between two others, then you can use this technique twice to find the 3/4 point. First find the halfway point between the start and end, then find the halfway point between that and the end - then you have the 3/4 point. – Jason Jan 21 '19 at 21:49
  • Also, this page (https://www.movable-type.co.uk/scripts/latlong.html) might have formulae that could help. In particular, search on that page for this text: "An intermediate point at any fraction along the great circle path between two points can also be calculated" – Jason Jan 21 '19 at 21:49

0 Answers0