We compute the great circle distance between two places on the earth. Input in degrees, output in miles.
let here = [45.470493,-122.7486358] let there = [44.5223676,-122.6336633]
let rad = (deg) => 2 * Math.PI * deg / 360 let sin = Math.sin let cos = Math.cos let acos = Math.acos
let [lat1,lon1] = here.map(deg => rad(deg)) let [lat2,lon2] = there.map(deg => rad(deg)) let earth = 3958.8 earth * acos( sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon1-lon2) )
http://js.ward.asia.wiki.org/assets/pages/snippet-template/basicjs.html?snippet-template HEIGHT 200
.
My interest in this formula comes from confirming that signal-to-noise variation of a nearby radio station was due to variation in the noise level, not the signal arriving by ground wave propagation. pdf
Ground wave: 30 miles at 14 MHz.
Radio station: 6.6 miles, not the 11 miles by road.