diff --git a/addons/weather/functions/fnc_calculateHeatIndex.sqf b/addons/weather/functions/fnc_calculateHeatIndex.sqf index 4605213e24..95060bd0a2 100644 --- a/addons/weather/functions/fnc_calculateHeatIndex.sqf +++ b/addons/weather/functions/fnc_calculateHeatIndex.sqf @@ -15,6 +15,16 @@ */ #include "script_component.hpp" +#define __C1 -8.784695 +#define __C2 1.61139411 +#define __C3 2.338549 +#define __C4 -0.14611605 +#define __C5 -0.012308094 +#define __C6 -0.016424828 +#define __C7 0.002211732 +#define __C8 0.00072546 +#define __C9 -0.000003582 + PARAMS_2(_t,_rh); _rh = _rh * 100; // relative humidity in % diff --git a/addons/weather/functions/fnc_calculateWetBulb.sqf b/addons/weather/functions/fnc_calculateWetBulb.sqf index c044c2ed57..c180cf8384 100644 --- a/addons/weather/functions/fnc_calculateWetBulb.sqf +++ b/addons/weather/functions/fnc_calculateWetBulb.sqf @@ -4,7 +4,9 @@ * Calculates wet bulb based on temperature and relative humidity * * Arguments: - * + * 0: temperature - degrees celcius + * 1: pressure - hPa + * 2: relativeHumidity - value between 0.0 and 1.0 * * Return Value: * 0: wet bulb @@ -14,6 +16,26 @@ */ #include "script_component.hpp" -// TODO: ... +private ["_es", "_e", "_eDiff", "_eGuessPrev", "_cTempDelta", "_twGuess", "_eguess"]; -GVAR(currentTemperature) +PARAMS_3(_temperature,_pressure,_relativeHumidity); + +// Source: http://cosmoquest.org/forum/showthread.php?155366-Calculating-Wet-Bulb-Temperature-from-RH-amp-Dry-Bulb +_es = 6.112 * exp((17.67 * _temperature) / (_temperature + 243.5)); +_e = _es * _relativeHumidity; +_eDiff = _es - _e; +_eGuessPrev = _es; +_cTempDelta = 3.3145; +_twGuess = _temperature; + +for "_j" from 1 to 50 do { + _twGuess = _twGuess - _cTempDelta; + _eguess = 6.112 * exp((17.67 * _twGuess) / (_twGuess + 243.5)); + _eguess = _eguess - (_pressure * (_temperature - _twGuess) * 0.00066 * (1 + (0.00115 * _twGuess))); + _eDiff = _eguess - _e; + if (abs(_eDiff) <= 0.001) exitWith {}; + _cTempDelta = _eDiff / ((_eguessprev - _eguess) / _cTempDelta); + _eguessprev = _eguess; +}; + +_twGuess diff --git a/addons/weather/script_component.hpp b/addons/weather/script_component.hpp index bf16255590..edc1ac64d0 100644 --- a/addons/weather/script_component.hpp +++ b/addons/weather/script_component.hpp @@ -18,14 +18,3 @@ #define WATER_VAPOR_MOLAR_MASS 0.018016 #define DRY_AIR_MOLAR_MASS 0.028964 #define SPECIFIC_GAS_CONSTANT_DRY_AIR 287.058 - -// Heat index coefficients -#define __C1 -8.784695 -#define __C2 1.61139411 -#define __C3 2.338549 -#define __C4 -0.14611605 -#define __C5 -0.012308094 -#define __C6 -0.016424828 -#define __C7 0.002211732 -#define __C8 0.00072546 -#define __C9 -0.000003582