> > > So the question is: How can I easily calculate the distance and how
> > > many nautical miles are "out of reach" (thinking of e.g. radar systems)
> > > ?
> >
> > You can compute distance at an altitude using SimGear functions
>
> Ack, don't even *think* about doing the math in a GIS datum.
I agree. You don't need overkill here. A simple check of the bounding square
should work fine. Something like this:
/* Check if position 2 is within a square of side R nautical miles that has
position 1 at a corner. This is a fast approximation of checking the distance
between them, avoiding the use of trigonometric or sqrt functions. This
assumes latitude in the range (-90,90) and longitude (-180,180).
*/
bool IsWithinRMiles( double lat1, double lon1, double lat2, double lon2,
double R ) {
double nm_per_deg_lat = 60.313;
double nm_per_deg_lon = 60.109 - fabs(lat1 * 0.66788);
double lat_diff = fabs(lat1 - lat2);
double lon_diff = fabs(lon1 - lon2);
if (lon_diff > 180.0) lon_diff = 360.0 - lon_diff;
if ((lat_diff * nm_per_deg_lat) < R) {
if ((lon_diff * nm_per_deg_lon) < R) {
return true;
}
}
return false;
}
This should be good enough for deciding if object2 should be visible to
object1, as long the range you're checking for isn't too small. I would use
20 nm for a visibility test.
To get a more accurate distance check (for instance, radar range) you'll need
to call a sqrt function in the test:
if ( sqrt( (lat_diff * lat_diff * nm_per_deg_lat * nm_per_deg_lat) +
(lon_diff * lon_diff * nm_per_deg_lon * nm_per_deg_lon)) < R) {
return true;
}
To get even more accuracy you can use trigonometric functions in the
nm_per_deg calculations (see AIModel/AIBase.cxx for the feet_per_deg
formulas).
Dave
_______________________________________________
Flightgear-devel mailing list
[email protected]
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d