Created
May 15, 2021 09:01
-
-
Save krisoft/4f06624a79f4a0df1107fb29be994a25 to your computer and use it in GitHub Desktop.
Calculating the distance between perseverance and zhurong rovers.
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
import math | |
MARS_RADIUS = 3389.5 # https://en.wikipedia.org/wiki/Mars | |
# source https://spacenews.com/chinas-zhurong-mars-rover-lands-safely-in-utopia-planitia/ | |
ZHURONG_LONGITUDE = 110.318 | |
ZHURONG_LATITUDE = 24.748 | |
# source https://www.jpl.nasa.gov/news/press_kits/mars_2020/launch/mission/landing_site/ | |
PERSEVERANCE_LONGITUDE = 77 | |
PERSEVERANCE_LATITUDE = 18 | |
# modified from https://stackoverflow.com/a/4913653 | |
def haversine(lon1, lat1, lon2, lat2, radius): | |
""" | |
Calculate the great circle distance between two points | |
on the earth (specified in decimal degrees) | |
""" | |
# convert decimal degrees to radians | |
lon1, lat1, lon2, lat2 = map(math.radians, [lon1, lat1, lon2, lat2]) | |
# haversine formula | |
dlon = lon2 - lon1 | |
dlat = lat2 - lat1 | |
a = math.sin(dlat/2)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon/2)**2 | |
c = 2 * math.asin(math.sqrt(a)) | |
return c * radius | |
if __name__=="__main__": | |
distance = haversine(ZHURONG_LONGITUDE, ZHURONG_LATITUDE, PERSEVERANCE_LONGITUDE, PERSEVERANCE_LATITUDE, MARS_RADIUS) | |
print( f"The distance between the zhurong and the perserverance rowers is {round(distance)} km." ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you Bill. It was just a quick sketch to calculate the approximate distance. I used it to show that it is very unlikely that these two robots can ever "visit" each other.
To do that the used precision was more than enough.
That being said thank you very much for the more precise values!