Every route out of one airport
Sixteen great-circle routes out of Heathrow, interpolated on the sphere with NumPy and handed to folium. The map is still a map: drag it, zoom it, click any city for its distance.
Every route out of one airport
The shortest path between two places on a globe is not the straight line you would draw on a flat map. It is an arc, and the further apart the endpoints are the more it bends.
This notebook computes those arcs with numpy and hands them to folium, which builds a Leaflet map and gives the notebook back a piece of HTML. The map below is that HTML, still live: drag it, zoom it, click any city.
1import folium2import numpy as np34R_KM = 6371.05HUB = ("London Heathrow", 51.4700, -0.4543)67CITIES = [8 ("New York", 40.6413, -73.7781),9 ("Los Angeles", 33.9416, -118.4085),10 ("Sao Paulo", -23.4356, -46.4731),11 ("Buenos Aires", -34.8222, -58.5358),12 ("Reykjavik", 63.9850, -22.6056),13 ("Lagos", 6.5774, 3.3212),14 ("Cape Town", -33.9649, 18.6017),15 ("Nairobi", -1.3192, 36.9278),16 ("Dubai", 25.2532, 55.3657),17 ("Mumbai", 19.0896, 72.8656),18 ("Singapore", 1.3644, 103.9915),19 ("Hong Kong", 22.3080, 113.9185),20 ("Tokyo", 35.5494, 139.7798),21 ("Sydney", -33.9399, 151.1753),22 ("Auckland", -37.0082, 174.7850),23 ("Vancouver", 49.1967, -123.1815),24]252627def to_vector(lat, lon):28 lat, lon = np.radians(lat), np.radians(lon)29 return np.array([np.cos(lat) * np.cos(lon), np.cos(lat) * np.sin(lon), np.sin(lat)])303132def great_circle(start, end, steps=72):33 """Walk the sphere from start to end, and report how far that was."""34 a, b = to_vector(*start), to_vector(*end)35 omega = np.arccos(np.clip(a @ b, -1.0, 1.0))36 t = np.linspace(0.0, 1.0, steps)[:, None]3738 arc = (np.sin((1 - t) * omega) * a + np.sin(t * omega) * b) / np.sin(omega)39 lat = np.degrees(np.arcsin(arc[:, 2]))40 # Unwrapped so a route crossing the date line keeps going instead of41 # snapping back across the whole map.42 lon = np.degrees(np.unwrap(np.arctan2(arc[:, 1], arc[:, 0])))43 return np.column_stack([lat, lon]), float(omega * R_KM)444546def band(km):47 if km < 3000:48 return "#2f6fd0"49 if km < 8000:50 return "#7b53c1"51 return "#c1440e"525354world = folium.Map(location=[24, 8], zoom_start=2, tiles="CartoDB positron")5556folium.CircleMarker(57 [HUB[1], HUB[2]], radius=8, color="#111", weight=2,58 fill=True, fill_color="#f5c542", fill_opacity=1.0, popup=HUB[0],59).add_to(world)6061for name, lat, lon in CITIES:62 arc, km = great_circle((HUB[1], HUB[2]), (lat, lon))63 folium.PolyLine(64 arc.tolist(), color=band(km), weight=1.8, opacity=0.8,65 ).add_to(world)66 folium.CircleMarker(67 [lat, lon], radius=4.5, color=band(km), weight=1.5,68 fill=True, fill_color=band(km), fill_opacity=0.9,69 popup=f"{name}: {km:,.0f} km",70 ).add_to(world)7172world
The bend is the point
Click Tokyo and the popup says a little under 9,600 km. Drawn as a straight line on this projection the route would head east across Asia; the arc goes north instead, over the Arctic, because that is genuinely the shorter way.
Color is distance: blue under 3,000 km, purple to 8,000, and rust beyond that. Here are the same numbers without a map.
1import matplotlib.pyplot as plt23distances = sorted(4 ((name, great_circle((HUB[1], HUB[2]), (lat, lon))[1]) for name, lat, lon in CITIES),5 key=lambda row: row[1],6)7names = [row[0] for row in distances]8kms = [row[1] for row in distances]910fig, ax = plt.subplots(figsize=(9, 5.2), constrained_layout=True)11ax.barh(names, kms, color=[band(km) for km in kms])12ax.set_xlabel("great-circle distance from Heathrow (km)")13ax.bar_label(ax.containers[0], fmt="%.0f", padding=4, fontsize=8)14ax.set_xlim(0, max(kms) * 1.12)15for side in ("top", "right"):16 ax.spines[side].set_visible(False)17plt.show()
Make it yours
Download the notebook and move HUB somewhere else. Every arc recomputes from
the sphere, so the picture reorganizes itself around the new origin, and the
antipode of wherever you pick becomes the point where routes stop bending in
any particular direction.
folium is one of several Python libraries that hand a notebook finished HTML
rather than an image. Verso shows that HTML as it is, which is why the map is
still a map here and not a screenshot of one.
Run it yourself
Nothing on this page is executable; the outputs were baked in by a real run. Download the notebook and it runs anywhere Verso does: VS Code, the browser, or the terminal.
dotnet tool install --global Verso.Cliverso serve flight-arcs.versoWhat this shows
Sixteen great-circle routes out of Heathrow, interpolated on the sphere with NumPy and handed to folium. The map is still a map: drag it, zoom it, click any city for its distance.
Every language in this notebook reads and writes the same variable store, so a value produced in one cell is simply there in the next, whatever the language.