Created
October 10, 2019 20:21
-
-
Save MiCurry/f096c31bb37a3d70e14e98a3c35f55ba to your computer and use it in GitHub Desktop.
Function to calculate a sphere distance
This file contains hidden or 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
def sphere_distance(lat1, lon1, lat2, lon2, radius, **kwargs): | |
""" Calculate the sphere distance between point1 and point2. | |
lat1 - Float - Radians - -pi:pi | |
lon1 - Float - Radians - 0:2*pi | |
lat2 - Float - Radians - -pi:pi | |
lon2 - Float - Radians - 0:2*pi | |
radius - Radius of the earth (or sphere) - Units can be ignored | |
""" | |
return (2 * radius * np.arcsin( | |
np.sqrt( | |
np.sin(0.5 * (lat2 - lat1))**2 | |
+ np.cos(lat1) | |
* np.cos(lat2) | |
* np.sin(0.5 * (lon2 - lon1))**2))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment