How the Haversine Formula Calculates Flight Distances Between Cities
Discover how the Haversine formula, rooted in centuries of navigation history, computes the shortest great‑circle distance between any two points on Earth, illustrated with Python code that measures distances and flight times among Beijing, Shanghai, Guangzhou, and Shenzhen.
1. History of Measuring Distance
In ancient times people estimated distances by walking or riding, but with the development of maps and mathematics more accurate methods emerged. The 16th‑century Age of Exploration made precise distance measurement crucial, using astronomical observations. The 18th century saw triangulation improve accuracy, and the 20th century introduced GPS for precise calculations.
2. Haversine Formula
Given the latitude and longitude of two points, the Haversine formula calculates the distance between them, allowing airlines to determine the shortest route, known as a great‑circle route.
The formula uses the differences in latitude (Δlat) and longitude (Δlon), the latitudes of the two points, the Earth’s radius (≈6371 km), and computes the central angle to obtain the distance.
3. Practical Application: Flight Route Selection
Airlines use the Haversine formula to find the shortest distance between airports, saving fuel, time, and cost.
To illustrate, the formula is applied to calculate distances among China’s four major cities: Beijing, Shanghai, Guangzhou, and Shenzhen.
4. Distance Calculations Between the Four Cities
<code>import math
# 定义哈弗赛恩公式函数
def haversine_distance(lat1, lon1, lat2, lon2):
R = 6371.0 # 地球半径,单位为公里
dlat = math.radians(lat2 - lat1)
dlon = math.radians(lon2 - lon1)
a = (math.sin(dlat / 2) ** 2 +
math.cos(math.radians(lat1)) * math.cos(math.radians(lat2)) *
math.sin(dlon / 2) ** 2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
distance = R * c
return distance
# 四大城市的经纬度
cities = {
"北京": (39.9042, 116.4074),
"上海": (31.2304, 121.4737),
"广州": (23.1291, 113.2644),
"深圳": (22.5431, 114.0579)
}
# 计算城市间的距离
distances = {}
city_names = list(cities.keys())
for i in range(len(city_names)):
for j in range(i+1, len(city_names)):
city1 = city_names[i]
city2 = city_names[j]
dist = haversine_distance(cities[city1][0], cities[city1][1], cities[city2][0], cities[city2][1])
distances[f"{city1}-{city2}"] = dist
distances
</code>Resulting distances:
Beijing‑Shanghai: ~1067.31 km
Beijing‑Guangzhou: ~1888.59 km
Beijing‑Shenzhen: ~1943.14 km
Shanghai‑Guangzhou: ~1211.89 km
Shanghai‑Shenzhen: ~1213.27 km
Guangzhou‑Shenzhen: ~104.20 km
Assuming a typical commercial jet cruises at 850 km/h, the estimated flight times are:
Beijing‑Shanghai: ~1.25 h
Beijing‑Guangzhou: ~2.22 h
Beijing‑Shenzhen: ~2.28 h
Shanghai‑Guangzhou: ~1.43 h
Shanghai‑Shenzhen: ~1.43 h
Guangzhou‑Shenzhen: ~0.12 h
Real flight data shows actual times are shorter because take‑off, landing, weather, and traffic control are not considered.
While technology makes physical distance seem small, personal circumstances often keep us from traveling home as often as we wish.
Model Perspective
Insights, knowledge, and enjoyment from a mathematical modeling researcher and educator. Hosted by Haihua Wang, a modeling instructor and author of "Clever Use of Chat for Mathematical Modeling", "Modeling: The Mathematics of Thinking", "Mathematical Modeling Practice: A Hands‑On Guide to Competitions", and co‑author of "Mathematical Modeling: Teaching Design and Cases".
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.