All pastes #22581 Raw Edit

Unnamed

public text v1 · immutable
#22581 ·published 2005-09-10 15:49 UTC
rendered paste body
#!/usr/bin/awk -f
                                                          
# math_earth_coordinates.awk - math the distance between latitude/longitude coords
#
# example on request by gnubien/#bash
# by xmb{@skilled.ch}
#
# 10/09/2005 - made off math code given

BEGIN {
        if (! lat1 && lat1 != "0") lat1 = 28.1028 * 0.017453293
        if (! lon1 && lon1 != "0") lon1 = -80.6458 * 0.017453293
        R = 3956
}
 
{ lat2 = $2 ; lon2 = $1 ; some_math() }

function some_math() {
        if ( lon1 < lon2) dlon = lon2 - (lon1 * -1)
        if ( lon1 > lon2) dlat = lat1 - (lat2 * -1)
#        dlon = lon2 - lon1
#        dlat = lat2 - lat1

        a = (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
        c = 2 * atan2(sqrt(a), sqrt(1-a))
        d = R * c

        # print here
        print d, c, a
}