Loading [MathJax]/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ALMaSS_MathFuncs Class Reference

ALMaSS_MathFuncs constructor. More...

#include <Misc.h>

Public Member Functions

 ALMaSS_MathFuncs ()
 ALMaSS_MathFuncs constructor. More...
 
virtual ~ALMaSS_MathFuncs ()
 ALMaSS_MathFuncs deconstructor. More...
 
int CalcDistPythagoras (int a_x, int a_y, int a_x1, int a_y1)
 Calculate distance using Pythagoras. More...
 
int CalcDistPythagorasApprox (int a_x, int a_y, int a_x1, int a_y1)
 Calculate distance using the Pythagoras approximation. More...
 

Detailed Description

ALMaSS_MathFuncs constructor.

Constructor & Destructor Documentation

◆ ALMaSS_MathFuncs()

ALMaSS_MathFuncs::ALMaSS_MathFuncs ( )
inline

ALMaSS_MathFuncs constructor.

This class is designed to hold general math functions frequently used in the ALMaSS code. For example distance calculations using either Pythagoras or the approximation of Pythagoras

35  {
36  ;
37  }

◆ ~ALMaSS_MathFuncs()

virtual ALMaSS_MathFuncs::~ALMaSS_MathFuncs ( )
inlinevirtual

ALMaSS_MathFuncs deconstructor.

39  {
40  ;
41  };

Member Function Documentation

◆ CalcDistPythagoras()

int ALMaSS_MathFuncs::CalcDistPythagoras ( int  a_x,
int  a_y,
int  a_x1,
int  a_y1 
)

Calculate distance using Pythagoras.

41  {
42  int dx = a_x - a_x1;
43  int dy = a_y - a_y1;
44  int dist = (int)sqrt( (double)(dx*dx + dy*dy) );
45  return dist;
46 }

◆ CalcDistPythagorasApprox()

int ALMaSS_MathFuncs::CalcDistPythagorasApprox ( int  a_x,
int  a_y,
int  a_x1,
int  a_y1 
)

Calculate distance using the Pythagoras approximation.

The approximation to Pythagorus is accurate to around 6%

48  {
52  int dx = abs( a_x - a_x1 );
53  int dy = abs( a_y - a_y1 );
54  dx++; //To avoid division by zero
55  dy++;
56  int dist;
57  if (dx>dy) {
58  dist = dx + (dy * dy) / (2 * dx);
59  }
60  else dist = dy + (dx * dx) / (2 * dy);
61  return dist;
62 }

The documentation for this class was generated from the following files: