]> git.mxchange.org Git - flightgear.git/blobdiff - src/FDM/YASim/Atmosphere.cpp
simplify name/number handling
[flightgear.git] / src / FDM / YASim / Atmosphere.cpp
index bc8a754dd780e74f41d303cecb0a08284bd0851c..92d2fbe56a6e3495762d2c2ffff5c96c42e134e8 100644 (file)
@@ -1,5 +1,3 @@
-#include <Main/fg_props.hxx>
-
 #include "Math.hpp"
 #include "Atmosphere.hpp"
 namespace yasim {
@@ -42,32 +40,24 @@ const float GAMMA = 1.4f;
 
 float Atmosphere::getStdTemperature(float alt)
 {
-    if (fgGetBool("/environment/params/control-fdm-atmosphere"))
-        return fgGetDouble("/environment/temperature-degC") + 273.15;
-    else
-        return getRecord(alt, 1);
+    return getRecord(alt, 1);
 }
 
 float Atmosphere::getStdPressure(float alt)
 {
-    if (fgGetBool("/environment/params/control-fdm-atmosphere"))
-        return fgGetDouble("/environment/pressure-inhg") * 3386.39;
-    else
-        return getRecord(alt, 2);
+    return getRecord(alt, 2);
 }
 
 float Atmosphere::getStdDensity(float alt)
 {
-    if (fgGetBool("/environment/params/control-fdm-atmosphere"))
-        return fgGetDouble("/environment/density-slugft3") * 515.378;
-    else
-        return getRecord(alt, 3);
+    return getRecord(alt, 3);
 }
 
-float Atmosphere::calcVEAS(float spd, float pressure, float temp)
+float Atmosphere::calcVEAS(float spd,
+                           float pressure, float temp, float density)
 {
     static float rho0 = getStdDensity(0);
-    float densityRatio = calcDensity(pressure, temp) / rho0;
+    float densityRatio = density / rho0;
     return spd * Math::sqrt(densityRatio);
 }
 
@@ -102,7 +92,7 @@ float Atmosphere::calcVCAS(float spd, float pressure, float temp)
     return Math::sqrt((7*p0/rho0)*(tmp-1));
 }
 
-float Atmosphere::calcDensity(float pressure, float temp)
+float Atmosphere::calcStdDensity(float pressure, float temp)
 {
     return pressure / (R * temp);
 }
@@ -112,6 +102,25 @@ float Atmosphere::calcMach(float spd, float temp)
     return spd / Math::sqrt(GAMMA * R * temp);
 }
 
+float Atmosphere::spdFromMach(float mach, float temp)
+{
+    return mach * Math::sqrt(GAMMA * R * temp);
+}
+
+float Atmosphere::spdFromVCAS(float vcas, float pressure, float temp)
+{
+                                // FIXME: does not account for supersonic
+    float p0 = getStdPressure(0);
+    float rho0 = getStdDensity(0);
+
+    float tmp = (vcas*vcas)/(7*p0/rho0) + 1;
+    float cp = ((Math::pow(tmp,(7/2.))-1)/(pressure/p0)) + 1;
+
+    float m2 = (Math::pow(cp,(1/3.5))-1)/0.2;
+    float vtas= spdFromMach(Math::sqrt(m2), temp);
+    return vtas;
+}
+
 void Atmosphere::calcStaticAir(float p0, float t0, float d0, float v,
                                float* pOut, float* tOut, float* dOut)
 {