def average_location(lat1,lon1,lat2,lon2,frac):
lat1=math.radians(lat1)
lon1=math.radians(lon1)
lat2=math.radians(lat2)
lon2=math.radians(lon2)
# Turn coordinates in radians to coordinates in 3-dimensional space
# See accompanying sketches for details
x1 = math.cos(lat1)*math.sin(lon1)
y1 = math.sin(lat1)
z1 = math.cos(lon1)*math.cos(lat1)
x2 = math.cos(lat2)*math.sin(lon2)
y2 = math.sin(lat2)
z2 = math.cos(lon2)*math.cos(lat2)
# Calculate distance between the two points (in the 3d space) in a straight line
MA = (((x1-x2)**2)+((y1-y2)**2)+((z1-z2)**2))**0.5
# The angle we're looking for is two times the inverse sine of half of that distance
alpha = math.asin(MA/2)*2
# The full distance between the two coordinates
full_distance = alpha * r
print("The distance between the two points is: %s" % (full_distance))
# If on the sphere, the distance should be frac, what should
# be the frac on the straight line connecting the two points?
gamma = (math.pi-alpha)/2
alpha1 = alpha * (1-frac)
beta = math.pi-alpha1-gamma
MF = math.sin(alpha1)/math.sin(beta)
frac_real = (MA-MF)/MA
# Point F lies at frac_real of MA
x3 = x1 + frac_real*(x2-x1)
y3 = y1 + frac_real*(y2-y1)
z3 = z1 + frac_real*(z2-z1)
# The radius is 1. So dividing point F (x,y,z)
# with it's distance from O, you get point F'
distance_to_origin = (((x3**2+z3**2)**0.5)**2+y3**2)**0.5
x3 = x3/distance_to_origin
y3 = y3/distance_to_origin
z3 = z3/distance_to_origin
# Turning the 3d space back to coordinates
# (basically reverting what happens above)
lat3 = math.asin(y3)
lon3 = math.asin(x3/math.cos(lat3))
# Printing latitude, longitude
lat_average=(lat3/(2*math.pi))*360
lon_average=(lon3/(2*math.pi))*360
print("%s%% of %s is %s" % (frac*100,full_distance,frac*full_distance))
print("%s from point 1, is %s°N and %s°E" % (frac*full_distance, lat_average,lon_average))
lat_medellin = 6.246236906580691
lon_medellin = -75.5715966473171
lat_amsterdam = 52.36808956713812
lon_amsterdam = 4.901112303056097
average_location(lat_amsterdam,lon_amsterdam,lat_medellin,lon_medellin,0.23)
I'm almost on top of the midoceanic ridge.
It has, overall, cost 24 tonnes of CO2.
Average annual per capita CO2 emissions in the Netherlands: 8.5 tonnes.
Average annual per capita CO2 emissions in Colombia: 1.9 tonnes.