X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNavaids%2Fmkrbeacons.cxx;h=a843d3f48ba58e6755b263c62944a3abc74a4e44;hb=5ea9c04c644a7e115f651132a6179d4e9d1ef8ce;hp=a3e8d33ed5f7bc947fdfb266649f5628989d5a88;hpb=22d044865749beab4380d1d08706a9a37e99476f;p=flightgear.git diff --git a/src/Navaids/mkrbeacons.cxx b/src/Navaids/mkrbeacons.cxx index a3e8d33ed..a843d3f48 100644 --- a/src/Navaids/mkrbeacons.cxx +++ b/src/Navaids/mkrbeacons.cxx @@ -36,7 +36,7 @@ FGBeacon::FGBeacon( double _lon, double _lat, double _elev, 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(); @@ -82,7 +82,7 @@ bool FGMarkerBeacons::add( double lon, double lat, double elev, 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; @@ -90,7 +90,7 @@ bool FGMarkerBeacons::add( double lon, double lat, double elev, 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; @@ -139,14 +139,14 @@ FGBeacon::fgMkrBeacType FGMarkerBeacons::query( double lon, double lat, 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; @@ -160,7 +160,7 @@ FGBeacon::fgMkrBeacType FGMarkerBeacons::query( double lon, double lat, 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; @@ -172,10 +172,10 @@ FGBeacon::fgMkrBeacType FGMarkerBeacons::query( double lon, double lat, // 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; @@ -184,23 +184,34 @@ FGBeacon::fgMkrBeacType FGMarkerBeacons::query( double lon, double lat, 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 ) { - // cout << "lon = " << lon << " lat = " << lat - // << " closest beacon = " << sqrt( min_dist ) << endl; + 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; + cout << "lon = " << lon << " lat = " << lat + << " closest beacon = " << sqrt( min_dist ) << endl; return FGBeacon::NOBEACON; }