Write a program that computes the spherical distance between two points on the surface of the Earth,
Question:
Write a program that computes the spherical distance between two points on the surface of the Earth, given their latitudes and longitudes. This is a useful operation because it tells you how far apart two cities are if you multiply the distance by the radius of the Earth, which is roughly
Let φ1, λ1, and φ2, λ2 be the latitude and longitude of two points, respectively. Δλ the longitudinal difference, and Δσ the angular difference/distance in radians, can be determined as follows from the spherical law of cosines:
△σ = arccos(sinφ1sinφ2 + cosφ2cosφ2cos △λ)
For example, consider the latitude and longitude of two major cities:
Nashville, TN: N 36∘7.2',W 86∘40.2'
Los Angeles, CA: N 33∘56.4',W 118∘24.0'
You must convert these coordinates to radians before you can use them effectively in the formula. After conversion, the coordinates become
Using these values in the angular distance equation, you get
r△σ = 6372.795 × 0.45306 = 2887.259 km
Thus, the distance between these cities is about 2887 km, or 1794 miles.
Step by Step Answer:
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp