Simple calculation that for some reason I'm getting very wrong:
def convert_to_vector(r, lat, long): x = r*math.cos(lat)*math.cos(long) y = r*math.cos(lat)*math.sin(long) z = r*math.sin(lat) return x, y, zdef convert_to_lat_long(x, y, z): r = math.sqrt(math.pow(x, 2)+math.pow(y, 2)+math.pow(z, 2)) lat = math.acos(z/r)*180/math.pi long = math.atan2(x, y)*180/math.pi return lat, longdef convert_to_dec_degrees(deg, minutes, sec, direction): dec = deg + minutes/60 + sec/3600 if direction == 'S' or direction == 'W': dec *= -1 return deckansas_city = [convert_to_dec_degrees(39, 5, 59, 'N'), convert_to_dec_degrees(94, 34, 41, 'W')]vector1 = convert_to_vector(1, kansas_city[0], kansas_city[1])k_city_latlon = convert_to_lat_long(vector1[0], vector1[1], vector1[2])print(kansas_city)print([k_city_latlon[0], k_city_latlon[1]])I can't tell which function is giving me the trouble, but I suspect its the conversion back to lat/lon.
The results print to console are:
[39.099722222222226, -94.57805555555555][9.7509365327902, 108.92341788716132]
أكثر...
def convert_to_vector(r, lat, long): x = r*math.cos(lat)*math.cos(long) y = r*math.cos(lat)*math.sin(long) z = r*math.sin(lat) return x, y, zdef convert_to_lat_long(x, y, z): r = math.sqrt(math.pow(x, 2)+math.pow(y, 2)+math.pow(z, 2)) lat = math.acos(z/r)*180/math.pi long = math.atan2(x, y)*180/math.pi return lat, longdef convert_to_dec_degrees(deg, minutes, sec, direction): dec = deg + minutes/60 + sec/3600 if direction == 'S' or direction == 'W': dec *= -1 return deckansas_city = [convert_to_dec_degrees(39, 5, 59, 'N'), convert_to_dec_degrees(94, 34, 41, 'W')]vector1 = convert_to_vector(1, kansas_city[0], kansas_city[1])k_city_latlon = convert_to_lat_long(vector1[0], vector1[1], vector1[2])print(kansas_city)print([k_city_latlon[0], k_city_latlon[1]])I can't tell which function is giving me the trouble, but I suspect its the conversion back to lat/lon.
The results print to console are:
[39.099722222222226, -94.57805555555555][9.7509365327902, 108.92341788716132]
أكثر...