Calculate distance between two coordinates with depth

108 Ansichten (letzte 30 Tage)
Feliciano Döring
Feliciano Döring am 30 Mai 2018
Beantwortet: Rob Comer am 29 Apr. 2022
I need to do what's in the title. I saw a file exchange about calculating the distance between two coordinates, but how would i do it considering the altitude? I have my data in latitude and longitude so i would need something to convert it first, i saw online and doing it one by one would take to long
  2 Kommentare
Ameer Hamza
Ameer Hamza am 30 Mai 2018
What do you mean by "considering the altitude". Give an example to clarify your question.
Feliciano Döring
Feliciano Döring am 30 Mai 2018
Bearbeitet: Feliciano Döring am 30 Mai 2018
I mean 3D,for example if i have the coordinates for latitude, longitude and heigth

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Kai Domhardt
Kai Domhardt am 30 Mai 2018
If I understand your question right, the solution should be to use the Haversine formula to get the 2D distance on the sphere and then use Pythagoras theorem with the difference in altitude.
dist_sphere = haversine(loc1(1:2), loc2(1:2));
delta_altitude = loc1(3)-loc2(3);
dist = sqrt( dist_sphere^2 + delta_altitude ^2 )
  3 Kommentare
Kelly Kearney
Kelly Kearney am 30 Mai 2018
Keep in mind that the Haversine formulation calculates the distance along a sphere (i.e. a rough approximation of great circle distance along the surface), not the straight line distance between the points. That may be what you want, but if you're instead looking for a straight line distance (i.e line through the earth to connect points on opposite sides of the globe rather than line encircling the earth), there are lots of different coordinate transformation options in the Mapping Toolbox.
Feliciano Döring
Feliciano Döring am 1 Jun. 2018
Bearbeitet: Feliciano Döring am 1 Jun. 2018
Yes, i actually am looking for something to connect directly, i'm dealing with waves inside the earth that travel directly an not through the surface

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Rob Comer
Rob Comer am 29 Apr. 2022
As Dr. Kearney suggested, the Mapping Toolbox can help. If you have it, try using ecefOffset. It computes the 3-D offset vector between two points (or, element-wise, between two sets of points), in an Earth-Centered Earth-Fixed (ECEF) coordinate system. From there, it's just a matter of computing the length of the offset vector to obtain the distance.
[deltaX,deltaY,deltaZ] = ecefOffset(spheroid,lat1,lon1,h1,lat2,lon2,h2);
d = hypot(hypot(deltaX,deltaY),deltaZ);
As the syntax suggests, the points need to be specified relative to a reference spheroid. (In many cases, wgs84ellipsoid will give an appropriate value.) The latitudes and longitudes need to be in degrees, and the height units need to match spheroid.LengthUnit. The h1 and h2 inputs should be heights above the ellipsoid, so if the available altitude values are referenced to something else (e.g., Mean Sea Level or Ground Level), they should be converted first using a geoid model and/or terrain model.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by