// constructor
-FGBeacon::FGBeacon() {
- FGBeacon( 0, 0, 0, NOBEACON );
+FGMkrBeacon::FGMkrBeacon() {
+ FGMkrBeacon( 0, 0, 0, NOBEACON );
}
-FGBeacon::FGBeacon( double _lon, double _lat, double _elev,
+FGMkrBeacon::FGMkrBeacon( double _lon, double _lat, double _elev,
fgMkrBeacType _type ) {
lon = _lon;
lat = _lat;
elev = _elev;
type = _type;
- Point3D pos = sgGeodToCart(Point3D(lon * DEG_TO_RAD, lat * DEG_TO_RAD, 0));
+ Point3D pos = sgGeodToCart(Point3D(lon * SGD_DEGREES_TO_RADIANS, lat * SGD_DEGREES_TO_RADIANS, 0));
// cout << "pos = " << pos << endl;
x = pos.x();
y = pos.y();
}
// destructor
-FGBeacon::~FGBeacon() {
+FGMkrBeacon::~FGMkrBeacon() {
}
// real add a marker beacon
-bool FGMarkerBeacons::real_add( const int master_index, const FGBeacon& b ) {
+bool FGMarkerBeacons::real_add( const int master_index, const FGMkrBeacon& b ) {
// cout << "Master index = " << master_index << endl;
beacon_map[master_index].push_back( b );
// front end for add a marker beacon
bool FGMarkerBeacons::add( double lon, double lat, double elev,
- FGBeacon::fgMkrBeacType type ) {
+ FGMkrBeacon::fgMkrBeacType type ) {
double diff;
int lonidx = (int)lon;
diff = lon - (double)lonidx;
- if ( (lon < 0.0) && (fabs(diff) > FG_EPSILON) ) {
+ if ( (lon < 0.0) && (fabs(diff) > SG_EPSILON) ) {
lonidx -= 1;
}
double lonfrac = lon - (double)lonidx;
int latidx = (int)lat;
diff = lat - (double)latidx;
- if ( (lat < 0.0) && (fabs(diff) > FG_EPSILON) ) {
+ if ( (lat < 0.0) && (fabs(diff) > SG_EPSILON) ) {
latidx -= 1;
}
double latfrac = lat - (double)latidx;
latidx += 90;
int master_index = lonidx * 1000 + latidx;
- FGBeacon b( lon, lat, elev, type );
+ FGMkrBeacon b( lon, lat, elev, type );
// add to the actual bucket
real_add( master_index, b );
// returns marker beacon type if we are over a marker beacon, NOBEACON
// otherwise
-FGBeacon::fgMkrBeacType FGMarkerBeacons::query( double lon, double lat,
+FGMkrBeacon::fgMkrBeacType FGMarkerBeacons::query( double lon, double lat,
double elev ) {
double diff;
int lonidx = (int)lon;
diff = lon - (double)lonidx;
- if ( (lon < 0.0) && (fabs(diff) > FG_EPSILON) ) {
+ if ( (lon < 0.0) && (fabs(diff) > SG_EPSILON) ) {
lonidx -= 1;
}
lonidx += 180;
int latidx = (int)lat;
diff = lat - (double)latidx;
- if ( (lat < 0.0) && (fabs(diff) > FG_EPSILON) ) {
+ if ( (lat < 0.0) && (fabs(diff) > SG_EPSILON) ) {
latidx -= 1;
}
latidx += 90;
beacon_list_iterator current = beacons.begin();
beacon_list_iterator last = beacons.end();
- Point3D aircraft = sgGeodToCart(Point3D(lon*DEG_TO_RAD, lat*DEG_TO_RAD, 0));
+ Point3D aircraft = sgGeodToCart(Point3D(lon*SGD_DEGREES_TO_RADIANS, lat*SGD_DEGREES_TO_RADIANS, 0));
double min_dist = 999999999.0;
// cout << " aircraft = " << aircraft << " station = " << station
// << endl;
- double d = aircraft.distance3Dsquared( station );
+ double d = aircraft.distance3Dsquared( station ); // meters^2
// cout << " distance = " << d << " ("
- // << FG_ILS_DEFAULT_RANGE * NM_TO_METER
- // * FG_ILS_DEFAULT_RANGE * NM_TO_METER
+ // << FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER
+ // * FG_ILS_DEFAULT_RANGE * SG_NM_TO_METER
// << ")" << endl;
// cout << " range = " << sqrt(d) << endl;
min_dist = d;
}
- // cout << "elev = " << elev * METER_TO_FEET
+ // cout << "elev = " << elev * SG_METER_TO_FEET
// << " current->get_elev() = " << current->get_elev() << endl;
- double delev = elev * METER_TO_FEET - current->get_elev();
- double maxrange = 4200 * delev / 1000;
+ double delev = elev * SG_METER_TO_FEET - current->get_elev();
+
+ // max range is the area under r = 2.4 * alt or r^2 = 4000^2 - alt^2
+ // whichever is smaller. The intersection point is 1538 ...
+ double maxrange2; // feet^2
+ if ( delev < 1538.0 ) {
+ maxrange2 = 2.4 * 2.4 * delev * delev;
+ } else if ( delev < 4000.0 ) {
+ maxrange2 = 4000 * 4000 - delev * delev;
+ } else {
+ maxrange2 = 0.0;
+ }
+ maxrange2 *= SG_FEET_TO_METER * SG_FEET_TO_METER; // convert to meter^2
// cout << "delev = " << delev << " maxrange = " << maxrange << endl;
// match up to twice the published range so we can model
// reduced signal strength
- if ( d < maxrange * maxrange ) {
+ if ( d < maxrange2 ) {
// cout << "lon = " << lon << " lat = " << lat
// << " closest beacon = " << sqrt( min_dist ) << endl;
return current->get_type();
}
// cout << "lon = " << lon << " lat = " << lat
- << " closest beacon = " << sqrt( min_dist ) << endl;
+ // << " closest beacon = " << sqrt( min_dist ) << endl;
- return FGBeacon::NOBEACON;
+ return FGMkrBeacon::NOBEACON;
}