]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/JSBSim/FGJSBBase.h
Fix for bug 1304 - crash loading XML route
[flightgear.git] / src / FDM / JSBSim / FGJSBBase.h
index 69d9f9c09e950987817d1d67d014ed683b1fe545..3dd78df9d7bf228626fbd08154fca36f490e7975 100644 (file)
@@ -43,27 +43,21 @@ INCLUDES
 #include <string>
 #include <cmath>
 
+using std::min;
+using std::max;
+
 #include "input_output/string_utilities.h"
 
 #ifndef M_PI
 #  define M_PI 3.14159265358979323846
 #endif
-
-#if defined(_MSC_VER) && (_MSC_VER < 1300)
-namespace std
-{
-  template <class T> inline T max(const T& a, const T& b)
-  {
-    return (a > b) ? a : b;
-  }
-}
-#endif
+#define IDENT(a,b)      static const char* const (a)[] = {b,(a)[0]}
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 DEFINITIONS
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
 
-#define ID_JSBBASE "$Id: FGJSBBase.h,v 1.32 2011/06/13 11:47:04 jberndt Exp $"
+#define ID_JSBBASE "$Id: FGJSBBase.h,v 1.39 2014/01/13 10:45:59 ehofman Exp $"
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 FORWARD DECLARATIONS
@@ -79,7 +73,7 @@ CLASS DOCUMENTATION
 *   This class provides universal constants, utility functions, messaging
 *   functions, and enumerated constants to JSBSim.
     @author Jon S. Berndt
-    @version $Id: FGJSBBase.h,v 1.32 2011/06/13 11:47:04 jberndt Exp $
+    @version $Id: FGJSBBase.h,v 1.39 2014/01/13 10:45:59 ehofman Exp $
 */
 
 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -263,13 +257,43 @@ public:
     return kelvin - 273.15;
   }
 
+  /** Converts from feet to meters
+  *   @param measure The length in feet.
+  *   @return The length in meters. */
+  static double FeetToMeters (double measure) {
+    return measure*0.3048;
+  }
+
+  /** Calculate the calibrated airspeed from the Mach number. It uses the
+  *   Rayleigh formula for supersonic speeds (See "Introduction to Aerodynamics
+  *   of a Compressible Fluid - H.W. Liepmann, A.E. Puckett - Wiley & sons
+  *   (1947)" ยง5.4 pp 75-80)
+  *   @param mach  The Mach number
+  *   @param p     Pressure in psf
+  *   @param psl   Pressure at sea level in psf
+  *   @param rhosl Density at sea level in slugs/ft^3
+  *   @return The calibrated airspeed (CAS) in ft/s
+  * */
+  static double VcalibratedFromMach(double mach, double p, double psl, double rhosl);
+
+  /** Calculate the Mach number from the calibrated airspeed. For subsonic
+  * speeds, the reversed formula has a closed form. For supersonic speeds, the
+  * Rayleigh formula is reversed by the Newton-Raphson algorithm.
+  *   @param vcas  The calibrated airspeed (CAS) in ft/s
+  *   @param p     Pressure in psf
+  *   @param psl   Pressure at sea level in psf
+  *   @param rhosl Density at sea level in slugs/ft^3
+  *   @return The Mach number
+  * */
+  static double MachFromVcalibrated(double vcas, double p, double psl, double rhosl);
+
   /** Finite precision comparison.
       @param a first value to compare
       @param b second value to compare
       @return if the two values can be considered equal up to roundoff */
   static bool EqualToRoundoff(double a, double b) {
     double eps = 2.0*DBL_EPSILON;
-    return std::fabs(a - b) <= eps*std::max(std::fabs(a), std::fabs(b));
+    return std::fabs(a - b) <= eps * max(std::fabs(a), std::fabs(b));
   }
 
   /** Finite precision comparison.
@@ -278,7 +302,7 @@ public:
       @return if the two values can be considered equal up to roundoff */
   static bool EqualToRoundoff(float a, float b) {
     float eps = 2.0*FLT_EPSILON;
-    return std::fabs(a - b) <= eps*std::max(std::fabs(a), std::fabs(b));
+    return std::fabs(a - b) <= eps * max(std::fabs(a), std::fabs(b));
   }
 
   /** Finite precision comparison.