I've enclosed the latest version of the distance (and other calculations)
code i use. It converts lat,lon to a 3 vector equivalent so computations
can be defined easily in terms of dot and cross products. It also does a
first order correction of the latitude for the spheriod.
k
At 10:07 AM 3/7/2002, Chris Hopkins wrote:
>Hi -
>
>I'm not sure if the WGS84 distinguishes the coordinates from regular
>coordinates, but here is a method which computes (estimates really) the
>distance between two lat/lon coordinates:
>
> // 6367 is "standard" radius of earth in km
> // 1.852 is km per Nautical Mile; this converts R to radius in naut miles
> private final static double R = 6367.0 / 1.852;
> private final static double RADIANSPERDEGREE = 0.017453293;
>
> private double computeDistance(double lat1, double lon1, double lat2,
>double lon2)
> {
> // all values are of type "double"; lat1,lon1,lat2 and lon2 are the
> // coordinates we are using in the calculation, in RADIANS.
> // You will have to convert from degrees to radians using the
> // conversion factor, RADIANSPERDEGREE
> lat2 = lat2 * RADIANSPERDEGREE;
> lon2 = lon2 * RADIANSPERDEGREE;
>
> double dlon = lon2 - lon1; // difference in longitude
> double dlat = lat2 - lat1; // difference in latitude
>
> double a = (Math.sin(dlat/2.0)* Math.sin(dlat/2.0)) +
> (Math.cos(lat1) * Math.cos(lat2) *
> Math.sin(dlon/2.0) * Math.sin(dlon/2.0));
>
> double c = 2.0 * Math.asin(Math.sqrt(a));
>
> return (R * c); // Final distance is in nautical miles.
> }
>
>Hope that helps. I couldn't find any means of calculating distances between
>two lat/lon points in OpenMap so I borrowed one from the net. This gives the
>result in nautical miles.
>
> - Chris
>
> > -----Original Message-----
> > From: owner-openmap-users@bbn.com [mailto:owner-openmap-users@bbn.com]On
> > Behalf Of Gubler, Rüdiger
> > Sent: Thursday, March 07, 2002 8:57 AM
> > To: Openmap-Users (E-Mail)
> > Subject: Distance between 2 WGS84-LatLon Coordinates
> >
> >
> >
> > Hello,
> >
> > in which way can i calculate the distance
> > between two WGS84-LatLon Coordinates?
> >
> >
> > Thanks Rüdiger
> >
> > --
> > [To unsubscribe to this list send an email to "majdart@bbn.com"
> > with the following text in the BODY of the message "unsubscribe
> > openmap-users"]
>
>--
>[To unsubscribe to this list send an email to "majdart@bbn.com"
>with the following text in the BODY of the message "unsubscribe
>openmap-users"]
-- [To unsubscribe to this list send an email to "majdart@bbn.com" with the following text in the BODY of the message "unsubscribe openmap-users"]
This archive was generated by hypermail 2.1.8 : Thu May 12 2005 - 07:18:32 EDT