Skip to content

Instantly share code, notes, and snippets.

Last active October 6, 2020 05:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Calculates distance between two points using latitude and longitude in decimal degrees - IGOR Pro
// calculates spherical distance between two points on earth given coords in decimal degrees
// uses haversine formula
// radius of earth is taken to be 6371 km (IUGG/WGS-84 mean)
Function SphericalDistanceBetweenTwoPoints(lat1, long1, lat2, long2)
Variable lat1, long1, lat2, long2
// convert inputs in degrees to radians
lat1*= pi/180
long1*= pi/180
lat2*= pi/180
long2*= pi/180
Variable dlon = long1 - long2
Variable dlat = lat1 - lat2
Variable aa = ((sin(dlat / 2) ^ 2) + cos(lat1) * cos(lat2) * (sin(dlon / 2) ^ 2))
Variable cc = 2 * atan2(sqrt(aa), sqrt(1 - aa))
Variable dd = 6371 * cc
// return distance in metres
return dd * 1000
// 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])
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment