It's generally accepted that the oblateness of the planet is
irrelevant for these kind of distance estimations. It's only great
circle distance anyway, which doesn't mean much unless you're flying.
There isn't a straight line (or great circle) road between every two
points on the map. There also might be something like an ocean, cliff,
or mountain between those two points ;)

I'd HIGHLY recommend giving names to your constants though. The code
is pretty terrible from a readability standpoint because you don't
state what units you're working in nor is it stated what the constants
represent. Which one is the radius of the earth? Is it miles of
kilometers? etc.

I'd also encourage you to use more parentheses around your equations
so that it's obvious what's supposed to be multiplied and when.
Different programming languages have different operator precedence so
I'm always VERY suspicious of code that puts different operators next
to each other without parentheses to make it unambiguous.

-bob

On 12/14/06, Hauwert, Ralph <[EMAIL PROTECTED]> wrote:
> I might be mistaking but it looks like these formulas would suggest a
> perfectly round earth, or at least an equally "ratio'd" earth. I'm
> pretty sure it's not.
>
> Ralph.
>
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
> On Behalf Of Brian LeRoux
> Sent: donderdag 14 december 2006 2:36
> To: Open Source Flash Mailing List
> Subject: [osflash] distance between two points of lat/long
>
> Getting some slightly 'off' results...anyone w/ a little geodata
> experience up for checking my math here? Really appreciate any
> suggestions for improving the code here too!
>
> Cheers,
> Brian
>
>
>
> function distance( lat1:Number, lon1:Number, lat2:Number, lon2:Number,
> unit:String ):Number
>         {
>                 var theta = lon1 - lon2;
>                 var dist = Math.sin(deg2rad(lat1)) *
> Math.sin(deg2rad(lat2)) +
> Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
> Math.cos(deg2rad(theta))
>
>                 dist = Math.acos(dist)
>                 dist = rad2deg(dist)
>
>                 var theDistance = dist * 60 * 1.1515
>
>                 switch( unit )
>                 {
>                         case "K":
>                                 theDistance = distance * 1.609344
>                         break;
>
>                         case "N":
>                                 theDistance = distance * 0.8684
>                         break;
>                 }
>
>                 return theDistance
>         }
>
>         function deg2rad( n:Number ):Number
>         {
>                 return( n * Math.PI / 180 )
>         }
>
>         function rad2deg( n:Number ):Number
>         {
>                 return( n * 180 / Math.PI )
>         }
>
> _______________________________________________
> osflash mailing list
> [email protected]
> http://osflash.org/mailman/listinfo/osflash_osflash.org
>
> _______________________________________________
> osflash mailing list
> [email protected]
> http://osflash.org/mailman/listinfo/osflash_osflash.org
>

_______________________________________________
osflash mailing list
[email protected]
http://osflash.org/mailman/listinfo/osflash_osflash.org

Reply via email to