Calculating the distance between two points using the longitude latitude and elevation (elevation)

I am trying to calculate the distance between two points using latitude longitude and height (height).

I used the euclidean formula to get my distance:

D=√((Long1-Long2)²+(Lat1-Lat2)²+(Alt1-Alt2)²)

My points are geographic coordinates, and the flight altitude is my altitude. I have only lat and lng, I use GOOGLE API height to get my height.

I am developing an application that calculates my distance traveled (on my skis). Each application that I used gets a distance with height enabled. Like #Endomondo or #Garmin, I cannot get my distance in 2D space because the true distances will be different from the ones I returned.

Which formula would be best to calculate my distance? Of course, with the height included.

I am writing my application in Python using PostGis.

+1
source share
3 answers

You can get the correct calculation by translating your coordinates from Polar (long, lat, alt) to Cartesian (x, y, z) :

  • Let:
    polar_point_1 = (long_1, lat_1, alt_1)
    and
    polar_point_2 = (long_2, lat_2, alt_2)
  • Translate each point to this Cartesian equivalent using this formula:

    x = alt * cos(lat) * sin(long)
    y = alt * sin(lat)
    z = alt * cos(lat) * cos(long)
    

    and you will be p_1 = (x_1, y_1, z_1)and p_2 = (x_2, y_2, z_2)point respectively.

  • Finally, use the Euclidean formula:

    dist = sqrt((x_2-x_1)**2 + (y_2-y_1)**2 + (z_2-z_1)**2)
    
+2
source

, , . . (x, y, z) http://electron9.phys.utk.edu/vectors/3dcoordinates.htm. () .

# .

       double lat_1 = 18.457793 * (Math.PI / 180);
       double lon_1 = 73.3951930277778 *(Math.PI/180);
       double alt_1 = 270.146;

       double lat_2 = 18.4581253333333 * (Math.PI / 180);
       double lon_2 = 73.3963755277778 * (Math.PI / 180);
       double alt_2 = 317.473;

       const Double r = 6376.5 *1000;//redius of earth in meaters

       double x_1 = r * Math.Sin(lon_1) * Math.Cos(lat_1);
       double y_1 = r * Math.Sin(lon_1) * Math.Sin(lat_1);
       double z_1 = r * Math.Cos(lon_1);

       double x_2 = r * Math.Sin(lon_2) * Math.Cos(lat_2);
       double y_2 = r * Math.Sin(lon_2) * Math.Sin(lat_2);
       double z_2 = r * Math.Cos(lon_2);

       double dist = Math.Sqrt((x_2 - x_1) * (x_2 - x_1) + (y_2 - y_1) *    
                               (y_2 - y_1) + (z_2 - z_1) * (z_2 - z_1));
+1
source

Source: https://habr.com/ru/post/1683450/


All Articles