There is also a question about the efficiency of reading / understanding source code. Here is a real live example (code from the stacking question )
Original:
import math def midpoint(p1, p2): lat1, lat2 = math.radians(p1[0]), math.radians(p2[0]) lon1, lon2 = math.radians(p1[1]), math.radians(p2[1]) dlon = lon2 - lon1 dx = math.cos(lat2) * math.cos(dlon) dy = math.cos(lat2) * math.sin(dlon) lat3 = math.atan2(math.sin(lat1) + math.sin(lat2), math.sqrt((math.cos(lat1) + dx) * (math.cos(lat1) + dx) + dy * dy)) lon3 = lon1 + math.atan2(dy, math.cos(lat1) + dx) return(math.degrees(lat3), math.degrees(lon3))
Alternative:
from math import radians, degrees, sin, cos, atan2, sqrt def midpoint(p1, p2): lat1, lat2 = radians(p1[0]), radians(p2[0]) lon1, lon2 = radians(p1[1]), radians(p2[1]) dlon = lon2 - lon1 dx = cos(lat2) * cos(dlon) dy = cos(lat2) * sin(dlon) lat3 = atan2(sin(lat1) + sin(lat2), sqrt((cos(lat1) + dx) * (cos(lat1) + dx) + dy * dy)) lon3 = lon1 + atan2(dy, cos(lat1) + dx) return(degrees(lat3), degrees(lon3))
source share