Skip to content

Instantly share code, notes, and snippets.

# quantixed/haversine.ipf

Last active October 6, 2020 05:45
Show Gist options
• Save quantixed/b43c1ad516a0b6b8fbe87f1798da5509 to your computer and use it in GitHub Desktop.
Calculates distance between two points using latitude and longitude in decimal degrees - IGOR Pro
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 // 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 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])

### quantixed commented Oct 6, 2020

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