summaryrefslogtreecommitdiffstats
path: root/src/ballistics.c
diff options
context:
space:
mode:
authorhybrid <hybrid@hybridlabs.pro>2026-07-11 10:15:52 +0300
committerhybrid <hybrid@hybridlabs.pro>2026-07-11 10:15:52 +0300
commit866393b70f5baddcaf9571b7240ebd4ce44bc67c (patch)
treecac69c96fc074c64af54060a044474e40e7e46ad /src/ballistics.c
parent4e6026b12eb00ea5bdd6dece2dfc97ffe8c2fc87 (diff)
downloada3catragmx-866393b70f5baddcaf9571b7240ebd4ce44bc67c.tar.gz
a3catragmx-866393b70f5baddcaf9571b7240ebd4ce44bc67c.tar.bz2
a3catragmx-866393b70f5baddcaf9571b7240ebd4ce44bc67c.zip
add: tmp commit
Diffstat (limited to 'src/ballistics.c')
-rw-r--r--src/ballistics.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/ballistics.c b/src/ballistics.c
new file mode 100644
index 0000000..10d97da
--- /dev/null
+++ b/src/ballistics.c
@@ -0,0 +1,38 @@
+#include <math.h>
+
+#include "ballistics.h"
+#include "constants.h"
+#include "context.h"
+
+double atmospheric_correction(double ballistic_coefficient,
+ double temperature,
+ double pressure,
+ double relative_humidity,
+ AtmosphereModel atmosphere_model) {
+ double air_density = calculate_air_density(temperature, pressure, relative_humidity);
+
+ if (atmosphere_model == ICAO)
+ return (STD_AIR_DENSITY_ICAO / air_density) * ballistic_coefficient;
+ else
+ return (STD_AIR_DENSITY_ASM / air_density) * ballistic_coefficient;
+}
+
+double calculate_air_density(double temperature,
+ double pressure,
+ double relative_humidity) {
+ pressure = pressure * 100;
+
+ if (relative_humidity > 0.0) {
+ double p_sat = 610.78 * pow(10, (7.5 * temperature - 273.15) /
+ (temperature - 273.15 + 237.3));
+ double vapor_pressure = relative_humidity * p_sat;
+ double partial_pressure = pressure - vapor_pressure;
+
+ return fma(partial_pressure,
+ DRY_AIR_MOLAR_MASS,
+ vapor_pressure * WATOR_VAPOR_MOLAR_MASS)
+ / (UNIVERSAL_GAS_CONSTANT * temperature);
+ }
+ else
+ return pressure / (SPECIFIC_GAST_CONSTANT_DRY_AIR * temperature);
+}