Using the standard Haversine formula for calculating air distances on Earth, the distance between Cape Town (South Africa) and Juneau (Alaska) is calculated to be 16,638km.
However, we might also convert the spherical [r, lat, long] of the cities into 3D Cartesian coord [X, Y, Z] where origin is the center of the Earth.
Using discrete small steps, we might chop up the delta_lat and delta_long between Cape Town and Juneau into 1,000 small parts. Then, we can find the 3D-Cartesian coord [X,Y,Z] of each small part and calculate the normal Pythagorean distance between each, since the small parts are very nearly planar.
let resolution = 1000;
let del_lat = dlat/resolution;
let del_lon = dlon/resolution;
let tot = 0;
for(let i=0; i<resolution; i++)
{
let P1 = cartesian (lat1 + idel_lat , lon1 + idel_lon , RADIUS_EARTH);
let P2 = cartesian (lat1 + (i+1)del_lat, lon1 + (i+1)del_lon, RADIUS_EARTH);
tot += distance(P1, P2);
}
But, the answer using this method is calculated to be 18,137km. I couldn't understand what causes this difference? The second method basically chops the distance between Cape Town and Juneau into 1,000 small parts (I have tried 1,000,000 parts with same result), and calculate the standard Pythagorean ("ruler") distance in this small planar surface.
Method 2 should give the near exact Earth-surface distance between Cape Town and Juneau, no? If not, why?
Thank you for any help and pointers on this.