11#include " ../include/Math.h"
22#include " ../include/Properties.h"
3+ #include < cmath>
34
45Math::Math (/* args */ )
56{
@@ -19,18 +20,38 @@ double Math1::calculateKoef(float windSpeed, double slopeAngleRad) const
1920double Math1::calculateWindKoef (const cell *c, directions InvestigatedDirection) const
2021{
2122 auto wind = c->getWind ().get ();
23+ if (wind == nullptr ){
24+ return double (1 );
25+ }
2226 float angleRadians = wind->angleBetweenDirections (InvestigatedDirection) * pi () / 180 ;
2327 return std::exp (wind->getWindSpeed () * (cos (cos (angleRadians)) - 1 ));
2428}
2529
26- bool Math1::willSpread (const cell *c, directions InvestigatedDirection) const
30+ double Math1::calculateGroundSlopeKoef (directions InvestigatedDirection, int altitudeDifference) const
31+ {
32+ double coef = 0 ;
33+ if (InvestigatedDirection == directions::North || InvestigatedDirection == directions::West ||
34+ InvestigatedDirection == directions::East || InvestigatedDirection == directions::South)
35+ {
36+ coef = atan2 (static_cast <double >(altitudeDifference), static_cast <double >(cellSizeInMeters ()));
37+ }
38+ else
39+ {
40+ coef = atan2 (static_cast <double >(altitudeDifference), static_cast <double >(cellSizeInMeters () * sqrt (2.0 )));
41+ }
42+ return std::exp (0.5 * coef);
43+ }
44+
45+ bool Math1::willSpread (const cell *c, directions InvestigatedDirection, int altitudeDifference) const
2746{
2847 double fireKoeff = calculateWindKoef (c, InvestigatedDirection);
29- return int (fireKoeff * 100 ) + (rand () % 100 ) > ignitionPercentage ();
48+ double slopeKoeff = calculateGroundSlopeKoef (InvestigatedDirection, altitudeDifference);
49+ return int (fireKoeff * slopeKoeff * 100 ) + (rand () % 100 ) > ignitionPercentage ();
3050}
3151
32- bool Math1::willSpreadThroughOne (const cell *c, directions InvestigatedDirection) const
52+ bool Math1::willSpreadThroughOne (const cell *c, directions InvestigatedDirection, int altitudeDifference ) const
3353{
3454 double fireKoeff = calculateWindKoef (c, InvestigatedDirection);
35- return int (fireKoeff * 100 ) + (rand () % 30 ) > throughPercentage ();
55+ double slopeKoeff = calculateGroundSlopeKoef (InvestigatedDirection, altitudeDifference);
56+ return int (fireKoeff * slopeKoeff * 100 ) + (rand () % 30 ) > throughPercentage ();
3657}
0 commit comments