mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
parent
1fb9c4e4c5
commit
ced3206dcf
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: AverageAngle.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.1.2
|
||||
// PURPOSE: class for averaging angles
|
||||
// URL: https://github.com/RobTillaart/Arduino
|
||||
//
|
||||
@ -9,7 +9,7 @@
|
||||
//
|
||||
// 0.1.0 2017-11-21 initial version
|
||||
// 0.1.1 2017-12-09 fixed negative values of average
|
||||
//
|
||||
// 0.1.2 2018-03-30 added getAverageLength, getTotalLength + zero-test
|
||||
|
||||
#include "AverageAngle.h"
|
||||
|
||||
@ -30,8 +30,8 @@ void AverageAngle::add(float alpha, float length)
|
||||
{
|
||||
alpha *= (PI / 180.0);
|
||||
}
|
||||
_sumx += cos(alpha) * length;
|
||||
_sumy += sin(alpha) * length;
|
||||
_sumx += (cos(alpha) * length);
|
||||
_sumy += (sin(alpha) * length);
|
||||
_count++;
|
||||
}
|
||||
|
||||
@ -53,5 +53,16 @@ float AverageAngle::getAverage()
|
||||
return angle;
|
||||
}
|
||||
|
||||
float AverageAngle::getTotalLength()
|
||||
{
|
||||
if (_count == 0) return 0;
|
||||
return hypot(_sumy, _sumx);
|
||||
}
|
||||
|
||||
float AverageAngle::getAverageLength()
|
||||
{
|
||||
if (_count == 0) return 0;
|
||||
return hypot(_sumy, _sumx) / _count;
|
||||
}
|
||||
|
||||
// END OF FILE
|
@ -3,7 +3,7 @@
|
||||
//
|
||||
// FILE: AverageAngle.h
|
||||
// AUTHOR: Rob dot Tillaart at gmail dot com
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.1.2
|
||||
// PURPOSE: class for averaging angles
|
||||
// HISTORY: See AverageAngle.cpp
|
||||
//
|
||||
@ -18,9 +18,7 @@
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
|
||||
#include "Printable.h"
|
||||
|
||||
#define AVERAGE_ANGLE_LIB_VERSION "0.1.1"
|
||||
#define AVERAGE_ANGLE_LIB_VERSION "0.1.2"
|
||||
|
||||
class AverageAngle
|
||||
{
|
||||
@ -33,6 +31,10 @@ public:
|
||||
void reset();
|
||||
int count() { return _count; };
|
||||
float getAverage();
|
||||
|
||||
float getTotalLength();
|
||||
float getAverageLength();
|
||||
|
||||
enum AngleType type() { return _type; };
|
||||
|
||||
private:
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
},
|
||||
"version":"0.1.1",
|
||||
"version":"0.1.2",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
"export": {
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AverageAngle
|
||||
version=0.1.1
|
||||
version=0.1.2
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Library to average angles
|
||||
|
Loading…
Reference in New Issue
Block a user