yep my bad...that last pair should be longitude. :)
my point was the forumla that was previously posted didn't work. whether it
was a typo (like mine! :) ) or not, i'm not sure.
-----Original Message-----
From: Raymond B. [mailto:[EMAIL PROTECTED]]
Sent: Saturday, January 27, 2001 8:34 PM
To: CF-Talk
Subject: RE: The real distance formula
Well, it's been quite a while since I last delved into GIS and trig but here
goes.
The earth does not lend itself well to simple calculations, all the below
(except the last) assume a spherical earth and ignore any diffences in the
terrain, elevation, roadways, etc. That said, let's look at some formulas.
The formula given in the previous post [below] is a VERY UNRELIABLE way to
calculate distances (and the last lat_A, lat_B should be longitude). It's
based on the law of cosines for spherical trigonometry: Mathmatically it's
all there but for small distances the inverse cosine gives huge room for
roundoff error. In short there are much better solutions.
The haversine formula is probably most used.
latd = lat1 - lat2 ;
lond = lon1 - lon2 ;
a = (sin(latd/2)^2 + cos(lat1) * cos(lat2) * (sin(londd/2))^2 ;
c = 2 * atan(sqr(a)/sqr(1-a)) ;
R = 6367 ;
d = R * c ;
I broke the formula up into quit a few parts so you could better see what's
happening:
- 'land' and 'lond' are the differences in latitude and longitude
respecitively
- 'a' is the chord length between the points
- 'R' is the accepted radius of the earth (spherical model) 6367km
Feel free to make it all one line, just sub in for the variables. There are
of course some caveats with this, as with any other equation. As stated
before, the earth is assumed to be spherical: If your application requires
greater accuracy you can vary R in respect to latitude using the
eccentricity (0.08108) of the ellipsoid (earth), the equatorial radius
(6379km), and the polar radius (6357km). I won't get into that, as I really
don't remeber how it's done... my notes from school seem to indicate I was
more interested in the brunette sitting infront of me in that class at that
point... heh. Ohh.. and this equation doesn't deal well with antipodal
points (ie. exact oposite side of the earth) seems it can be off by a few
kilometers.
If you're dealing with very local distances you might want to consider
treating the earth as flat; it can actually yield more acurate results over
short distances due to the assumed R. Again, not going to bother explaining
this as I'm sure you can work out the math relatively easily for asimple
polar coordinate system.
Anyways, neat question... I've been meaning to brush up on my trig and this
gave me an excuse.
Later.
-----Original Message-----
From: Scott Weikert [mailto:[EMAIL PROTECTED]]
Sent: January 27, 2001 21:12
To: CF-Talk
Subject: Re: The real distance formula
That was me, who was asking....
But I'm glad you spoke up, because something I was wondering about the
formulas that were being tossed around. Do they handle the fact that two
sets of positions, with identical longitudes (east-west, right?) but
different latitu
des, would be a different distance?
For example, two sets of positions - both the same longitude, but latitudes
of several hundred miles difference - and two other positions, also the same
longitude, and the same distance apart north-south as the other two. The
northern set of positions would be a shorter distance apart than the
southern set... does the formula deal with that?
--Scott
----- Original Message -----
From: "Dylan Bromby" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Saturday, January 27, 2001 4:36 PM
Subject: The real distance formula
> A week or more ago, someone posted a formula for calculating the distance
> between two points using latitude/longitude. I think the formula as
> incorrect. However, here is one that works perfectly;
>
> #Evaluate(((pi()*6378)/180)*(ACos((Sin(lat_A)*Sin(lat_B)) +
> (Cos(lat_A)*Cos(lat_B)*Cos(lat_A-lat_B)))))#
>
> This yields distance in KM. If you want miles, do the calculation after
the
> fact, or change the value of 6378 - the earth's radius in KM - to a value
> in miles.
>
> --Dylan
>
>
>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists