Re: geography math?



David Gravereaux wrote:
> Helmut Jarausch wrote:
>
>>David Gravereaux wrote:
>>
>>
>>>I found this for calculating distance from 2 points given geographical
>>>coordinates, but it doesn't appear to give correct results at first
>>>glance.
>>>
>>>proc geographical_distance {lat1 long1 lat2 long2} {
>>> set pi [expr atan2(1,1) * 4]
>>>
>>> # assume the earth is a perfect sphere (miles)
>>> set r 3963.1
>>>
>>> # convert to radians
>>> set a1 [expr {$lat1*($pi/180)}]
>>> set b1 [expr {$long1*($pi/180)}]
>>> set a2 [expr {$lat2*($pi/180)}]
>>> set b2 [expr {$long2*($pi/180)}]
>>>
>>> # found @ http://jan.ucc.nau.edu/~cvm/latlon_formula.html
>>> #return [expr {acos(cos($a1)*cos($b1)*cos($a2)*cos($b2) + \
>>> cos($a1)*sin($b1)*cos($a2)*sin($b2) + sin($a1)*sin($a2)) * $r}]
>>>
>>> # found @ http://mathforum.org/library/drmath/view/51879.html
>>> set dlon [expr {$b2 - $b1}]
>>> set dlat [expr {$a2 - $a1}]
>>> set a [expr {pow((sin($dlat/2)),2) + \
>>> cos($a1)*cos($a2)*pow((sin($dlon/2)),2)}]
>>> set c [expr {2 * atan2(sqrt($a),sqrt(1-$a))}]
>>> return [expr {$r * $c}]
>>>}
>>>
>>>
>>>% geographical_distance 37.943591 -122.323258 37.111111 -120.157222
>>>with the first: 132.031435852
>>>with the second: 132.031435843
>>>
>>>
>>>Hmm.. My "reference" source says those points are 63.26 miles away from
>>>each other. Anyone have any thoughts on this? I think my reference one
>>>just might be wrong after all...
>>
>>
>>I don't know what your reference is.
>>The formula you have used looks like a spherical approximation to the
>>earth.
>
>
> yup.
>
>
>>But for higher precision you need an ellipsoidal approximation. But even
>>these
>>are not unique - (nearly) each country uses it own ellipsoidal
>>approximation.
>>Look for geodetic datum.
>>There is one exception: for world wide reference (e.g. UTM) the so-called
>>WGS84 datum is used. When using an ellipsoidal model of the earth, there
>>are
>>no closed form exact formulas. Using a very exact approximation and the
>>WGS84
>>system, I get 212582.7 m i.e. 132.0928 miles ( using 1 mile = 1609.344 m)
>>The quoted result of 63.26 miles is plain wrong, the differences caused
>>by using different ellipsoidal models is well below 0.5 miles.
>
>
>
> Helmut,
>
> Thanks for your input. Yes, looks like my "reference" is plain wrong.
> Excellent news. Four alternate checks with yours give me 132 mi, so
> that's good enough for me to call that reference broken. Thanks for the
> pointer to ellipsoid models, I'll check them out.
>
> "I test, therefore I am".


Wait a sec.. Something is terribly wrong here. I broke-out a printed
map and measured with some calipers to get an approximate distance from

+37° 56' 36.93", -122° 19' 23.73" to
+37° 45' 20.00", -122° 27' 5.00" (Sutro tower, SF, CA)

to be 15.09mi

My "reference" says those are 14.8mi apart. That's good, they verify.

Next I plugged those into my proc and got 44.26mi!! What the? Ok, what
did I do wrong? :)

Ahh.. My calculation from minutes/seconds into pure decimal degrees
went the wrong way.. Haha.. my bad. I found it be checking on
maps.google.com

[expr {-122+(27+(5/60.0))/60}] != -122.451389

changed to 'expr {-(abs(-122)+(27+(5/60.0))/60)}' to apply direction
after adding the decimal parts.

Silly me. A 6th grade math error on my part.
.



Relevant Pages

  • Re: geography math?
    ... Helmut Jarausch wrote: ... > I don't know what your reference is. ... > But for higher precision you need an ellipsoidal approximation. ... When using an ellipsoidal model of the earth, ...
    (comp.lang.tcl)
  • Re: Calculate the Circumference of an ellipse
    ... Hi J. Maybe we can expand your excellent reference to a Custom function. ... Here, we factor out a common expression, and add in the 2 Pi to get the Perimeter. ... I would say that's as good an approximation as it gets. ... gives me results shown on that same Wiki page for the various values of b with a value of 10000 for the major semi-axis value. ...
    (microsoft.public.excel.misc)
  • Re: asymptotic behaviour of multivariate recurrence equations?
    ... approximation it refers. ... In Fundamental Algorithms 3rd Edition there is one reference to the ... around it) there are only exact equations involving stirling numbers. ... In Graham Knuth Patashnik, Concrete Mathematics there is one referene to the ...
    (comp.theory)
  • Re: Value of "e" in the C log() function
    ... language uses in the logfunction. ... I ask as I am coparing the ... Any approximation of e used by a C implementation, however, /does/ ... develop that algorithm without reference to that base value. ...
    (comp.lang.c)