otamesi
Dependencies: mbed
Diff: Math.cpp
- Revision:
- 18:2a47ed430cfe
diff -r 9bc130ebb5ed -r 2a47ed430cfe Math.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Math.cpp Fri Nov 23 09:31:07 2018 +0000 @@ -0,0 +1,25 @@ +#include "Math.h" +#include "mbed.h" + +const float gPI = 3.1415926536f; + +float convertRange( float in, float oldMin, float oldMax, float newMin, float newMax ){ + return ( in - oldMin ) * ( newMax - newMin ) / ( oldMax - oldMin ) + newMin; +} + +float convertRangePlusMinusPi( float deg ){ + while ( ( deg > gPI ) || ( deg < -gPI ) ){ + while ( deg > gPI ){ + deg -= 2.0f * gPI; + } + while ( deg < -gPI ){ + deg += 2.0f * gPI; + } + } + + return deg; +} + +bool isNear( float a, float b, float error ){ + return ( abs( a - b ) < error ); +}