diff options
Diffstat (limited to 'calculator.go')
| -rw-r--r-- | calculator.go | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/calculator.go b/calculator.go index 84ed8c8..dd2b583 100644 --- a/calculator.go +++ b/calculator.go @@ -7,16 +7,18 @@ import ( ) // CalculateFeelsLike calculates apparent temperature +// windSpeed is expected in km/h func CalculateFeelsLike(temp, humidity, windSpeed float64) float64 { - if temp <= 10 && windSpeed > 1.34 { - // Wind chill formula for cold temperatures - return 13.12 + 0.6215*temp - 11.37*math.Pow(windSpeed, 0.16) + 0.3965*temp*math.Pow(windSpeed, 0.16) - } else if temp >= 27 { - // Simplified heat index for warm temperatures - e := humidity / 100 * 6.105 * math.Exp(17.27*temp/(237.7+temp)) - return temp + 0.33*e - 0.70*windSpeed - 4.00 - } - return temp + if temp <= 10 && windSpeed > 4.8 { + // Wind chill formula (Environment Canada, wind in km/h) + vPow := math.Pow(windSpeed, 0.16) + return 13.12 + 0.6215*temp - 11.37*vPow + 0.3965*temp*vPow + } else if temp >= 27 { + // Simplified heat index for humid heat (Steadman's approximation) + e := humidity / 100 * 6.105 * math.Exp(17.27*temp/(237.7+temp)) + return temp + 0.33*e - 0.70*windSpeed - 4.00 + } + return temp } // SunCalculator calculates sunrise and sunset times |
