On Sat, 2009-01-10 at 17:13 +0100, Csaba Halász wrote: > #2 0x000000000080188d in FGNavRadio::update (this=0x98df490, > dt=0.058333333333333334) at src/Instrumentation/navradio.cxx:613 > 613 double angle = asin( y / x ) * SGD_RADIANS_TO_DEGREES; > (gdb) p x > $1 = 3.2580450943147174 > (gdb) p y > $2 = 3.258443598627875 > (gdb) p y / x > $3 = 1.0001223139341602 > > No idea what it is calculating and how to fix. (apart from forcibly > clamping y/x to [-1, 1] ...)
This bug bit me today. I'm starting this thread from Csaba's first e-mail since the last thread missed the problem. More context code: double x = gs_dist_node->getDoubleValue(); double y = (fgGetDouble("/position/altitude-ft") - nav_elev) * SG_FEET_TO_METER; // cout << "dist = " << x << " height = " << y << endl; double angle = asin( y / x ) * SGD_RADIANS_TO_DEGREES; y is vertical distance, x is distance to the navaid. It appears the original author intended the "x" distance to be slant range. Hence we have (vertical rise)/(slant range) or rise/hypotenuse. As long as that is true, y/x will never exceed +/- 1 since the vertical rise must always be less than or equal to the slant range. However, I enabled the cout line and discovered x is indeed dropping below y. From observation "x" is horizontal distance not slant range. I think we need double angle = atan2( y, x ) * SGD_RADIANS_TO_DEGREES; Thanks, Ron
Index: src/Instrumentation/navradio.cxx =================================================================== RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/navradio.cxx,v retrieving revision 1.31 diff -u -b -r1.31 navradio.cxx --- src/Instrumentation/navradio.cxx 25 Dec 2008 23:11:44 -0000 1.31 +++ src/Instrumentation/navradio.cxx 2 Apr 2009 14:49:57 -0000 @@ -610,7 +610,7 @@ double y = (fgGetDouble("/position/altitude-ft") - nav_elev) * SG_FEET_TO_METER; // cout << "dist = " << x << " height = " << y << endl; - double angle = asin( y / x ) * SGD_RADIANS_TO_DEGREES; + double angle = atan2( y, x ) * SGD_RADIANS_TO_DEGREES; r = (target_gs - angle) * 5.0; r *= signal_quality_norm; }
------------------------------------------------------------------------------
_______________________________________________ Flightgear-devel mailing list Flightgear-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/flightgear-devel