#include #include "ballistics.h" #include "constants.h" #include "context.h" static inline double speed_of_sound(double temperature); static inline double calculate_retard(DragModel drag_function, double ballistic_coefficient, double velocity, double mach); 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); } static inline double speed_of_sound(double temperature) { return sqrt(331.3 * (1.0 + temperature - 273.15 / 273.15)); } static inline double calculate_retard(DragModel ballistic_model, double ballistic_coefficient, double velocity, double mach) { double m = velocity / mach; for (int i = 0 } double retard(DragModel ballistic_model, double ballistic_coefficient, double velocity, double temperature) { return calculate_retard(ballistic_model, ballistic_coefficient, velocity, speed_of_sound(temperature)); }