Calculating distance from longitude and latitude points

Hello,

I have three waves: latitude, longitude, and altitude.

I would like to know if there is IGOR code that would allow me to calculate the distance between each latitude and longitude point.

Thanks very much


My interpretation of the OP was that the altitude wasn't to be included in the distance: "calculate the distance between each latitude and longitude point". If that was the case then I would've written ""calculate the distance between each latitude/longitude/altitude point".

andyfaff wrote:
My interpretation of the OP was that the altitude wasn't to be included in the distance: "calculate the distance between each latitude and longitude point". If that was the case then I would've written ""calculate the distance between each latitude/longitude/altitude point".


You're right, of course. I was just pointing out what the algorithm was, and that it was for a constant altitude.

--Jim Prouty
Software Engineer, WaveMetrics, Inc.
What I don't understand about that formula is that the earth is not spherical, but more like an oblate ellipsoid. I don't see how that formula takes this into account.

A.
andyfaff wrote:
What I don't understand about that formula is that the earth is not spherical, but more like an oblate ellipsoid. I don't see how that formula takes this into account.

The Wikipedia article on Haverside does recognise this and provides a reference to Vincenty's formula which treats Earth as an oblate spheroid.
http://en.wikipedia.org/wiki/Vincenty%27s_formulae
This is an iterative algorithm, so somewhat more complicated to implement than the Haverside formula. Which is appropriate depends upon how accurate one needs the answer to be.
K

I needed to do this in Igor today and found this thread. The replies identified the answer but there was no solution posted. So , here is a quick function to do it:

// calculates spherical distance between two points on earth given coords in decimal degrees
// uses haversine formula
// radius of earth is taken to be 6375 km (approximate for London, UK)
Function DistanceBetweenTwoPoints(x0,y0,x1,y1)
    Variable x0,x1,y0,y1
   
    Variable dlon = pi * ((x1 - x0) / 180)
    Variable dlat = pi * ((y1 - y0) / 180)
    Variable aa = (sin(dlat / 2)) ^ 2 + cos(pi * (y0 / 180)) * cos(pi * (y1 / 180)) * (sin(dlon / 2)) ^ 2
    Variable cc = 2 * atan2(sqrt(aa), sqrt(1 - aa))
    Variable dd = 6375 * cc
   
    // return distance in metres
    return dd * 1000
end

// example usage with two 1D waves called lat and lon, distance between rows 0 and 1
Print DistanceBetweenTwoPoints(lon[0],lat[0],lon[1],lat[1])