- // derived from http://williams.best.vwh.net/avform.htm#Mach
- // names here are picked to be consistent with those formulae!
-
- double oatK = env.get_temperature_degc() + 273.15; // OAT in Kelvin
- double CS = 38.967854 * sqrt(oatK); // speed-of-sound in knots at altitude
- double CS_0 = 661.4786; // speed-of-sound in knots at sea-level
- double P_0 = env.get_pressure_sea_level_inhg();
- double P = _static_pressure_node->getDoubleValue();
+ double oatK = env.get_temperature_degc() + SG_T0_K - 15.0 ; // OAT in Kelvin
+ oatK = std::max( oatK , 0.001 ); // should never happen, but just in case someone flies into space...
+ double c = sqrt(SG_gamma * SG_R_m2_p_s2_p_K * oatK); // speed-of-sound in m/s at aircraft position
+ double pt = _total_pressure_node->getDoubleValue() * SG_INHG_TO_PA; // total pressure in Pa
+ double p = _static_pressure_node->getDoubleValue() * SG_INHG_TO_PA; // static pressure in Pa
+ p = std::max( p , 0.001 ); // should never happen, but just in case someone flies into space...
+ double rho = _density_node->getDoubleValue() * SG_SLUGFT3_TO_KGPM3; // air density in kg/m3
+ rho = std::max( rho , 0.001 ); // should never happen, but just in case someone flies into space...