
MnGCA Minnesota Geocaching Association

View previous topic :: View next topic 
Author 
Message 
SirPoonga Geocacher
Joined: 07 Feb 2003
Posts: 144 Location: Marshfield, WI :(

Posted: Wed Jun 09, 2004 10:23 pm Post subject: calculating distance 


I need to know how to calculate the distance between two waypoints, mathematically. I want to program something and need to know the mathematics behind it. I know it isn't simple because the somewhat spherical shape of the earth. I am having a hard time finding resources. 

Back to top 


rickrich Geocacher
Joined: 06 Jul 2003
Posts: 673

Posted: Thu Jun 10, 2004 5:32 am Post subject: 


From my "geodist" program at http://geo.rkkda.com. This should be good enough for government work. If you want a more accurate answer, check out Gazza's geodetics calculator.
BTW, around Mpls .001 minute is about 1.8m (5.9ft) NS, and 1.3m (4.26 feet) EW.
Code: 
#
# Rough calculation of distance on an ellipsoid
#
calc_dist_meters() {
awk \
v LATmin=$1 \
v LONmin=$2 \
v LATmax=$3 \
v LONmax=$4 \
'
function calcR(lat)
{
lat = lat * M_PI_180
sc = sin(lat)
x = A * (1.0  E2)
z = 1.0  E2 * sc * sc
y = z ^ 1.5
r = x / y
return r * 1000.0
}
function asin(x) { return atan2(x,(1.x^2)^0.5) }
function dist(lat1, lon1, lat2, lon2,
radiant, dlon, dlat, a1, a2, a, sa, c)
{
radiant = M_PI_180
dlon = radiant * (lon1  lon2);
dlat = radiant * (lat1  lat2);
a1 = sin(dlat / 2.0)
a2 = sin (dlon / 2.0)
a = (a1 * a1) + cos(lat1 * radiant) * cos(lat2 * radiant) * a2 * a2
sa = sqrt(a)
if (sa <= 1.0)
c = 2 * asin(sa)
else
c = 2 * asin(1.0)
return (Ra[int(100 + lat2)] + Ra[int(100 + lat1)]) * c / 2.0;
}
BEGIN {
A = 6378.137
E2 = 0.081082 * 0.081082
M_PI = 3.14159265358979323846
M_PI_180 = M_PI / 180.0
# Build array for earth radii
for (i = 100; i <= 100; i++)
Ra[i+100] = calcR(i)
d = dist(LATmin, LONmin, LATmax, LONmax)
printf "%d\n", d
}
'
}



Back to top 


sui generis Past MnGCA Board
Joined: 17 Apr 2004
Posts: 608 Location: Eagan, MN

Posted: Thu Jun 10, 2004 5:44 am Post subject: 


....did you remember to carry the 1? _________________ I am amazed by how many people harp on the need to speak and write English in this country while exhibiting a fundamental lack of skills in the areas of spelling and sentence composition. Would this be irony, hypocrisy, or both? 

Back to top 


SirPoonga Geocacher
Joined: 07 Feb 2003
Posts: 144 Location: Marshfield, WI :(

Posted: Sun Jun 13, 2004 10:07 pm Post subject: 


rick, I ggotta find the link to your site again, I know if I look around here enough I will find it. Do you have the source available for your programs? I have a tbug idea and I am working on a way to track how the tbugs spread using svg like gps visualizer. But I to know/figure out the algorithms used to figure out what size of map to use, etc..... 

Back to top 


Marsha and Silent Bob Past MnGCA President
Joined: 02 Sep 2003
Posts: 6261

Posted: Mon Jun 14, 2004 5:30 am Post subject: 


SirPoonga wrote: 
rick, I ggotta find the link to your site again, I know if I look around here enough I will find it. Do you have the source available for your programs? I have a tbug idea and I am working on a way to track how the tbugs spread using svg like gps visualizer. But I to know/figure out the algorithms used to figure out what size of map to use, etc..... 
http://mngca.rkkda.com/
Yeah the source is there too. _________________ Sad state of affairs. 

Back to top 




You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum

Powered by phpBB © 2001, 2002 phpBB Group Geocaching Cache Icons, Copyright 2009, Groundspeak Inc. All rights reserved. Used with Permission.
