PDA

View Full Version : Calculating radius width

hegdek
12-02-2006, 12:32 PM
Hi friends,
If i draw a radius and i right click,how do i find out programatically,that
a particular latitude and longitiude falls within the radius.
regards
kaushik

Wilfried
12-02-2006, 02:40 PM
Hi,

- 1 arc second is exacly 1 sea mile on equator and in latitude
- in longitude if not on equator multiply with Cos(latitude)

So you know the center of the circle, and you can calculate the distance.

Wait, I give you a peace of code that calculate the distance to 2 point. It is in one of my boardcomputers to calculate birds view distance. It is in c but you can easy convert it. Dont mind the bearing, you need de distance:

u_16 get_bearing(double lat1, double lon1, double lat2, double lon2, u_32* miles)
{
double lat = lat2 - lat1;
double lon = (lon2 - lon1) * cos(deg2rad((lat1 + lat2) / 2));
double dist = hypot(lat, lon);
double bear = rad2deg(acos(lat / dist));

if (nv->par.km)
*miles = (u_32)(dist * 60 * 10 * 1.852);
else
*miles = (u_32)(dist * 60 * 10 * 1.852 / 1.609);

if (lon < 0) // Western direction
bear = 360 - bear;
return bear;
}