This repository has been archived on 2020-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
Files
Indoor/sensors/imu/GravityData.h
2018-10-25 11:50:12 +02:00

78 lines
1.7 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* © Copyright 2014 Urheberrechtshinweis
* Alle Rechte vorbehalten / All Rights Reserved
*
* Programmcode ist urheberrechtlich geschuetzt.
* Das Urheberrecht liegt, soweit nicht ausdruecklich anders gekennzeichnet, bei Frank Ebner.
* Keine Verwendung ohne explizite Genehmigung.
* (vgl. § 106 ff UrhG / § 97 UrhG)
*/
#ifndef GRAVITYDATA_H
#define GRAVITYDATA_H
#include <cmath>
#include <sstream>
#include "../../math/Floatingpoint.h"
/** data received from an accelerometer sensor */
struct GravityData {
FPDefault x;
FPDefault y;
FPDefault z;
GravityData() : x(0), y(0), z(0) {;}
GravityData(const float x, const float y, const float z) : x(x), y(y), z(z) {;}
FPDefault magnitude() const {
return std::sqrt( x*x + y*y + z*z );
}
GravityData& operator += (const GravityData& o) {
this->x += o.x;
this->y += o.y;
this->z += o.z;
return *this;
}
GravityData& operator -= (const GravityData& o) {
this->x -= o.x;
this->y -= o.y;
this->z -= o.z;
return *this;
}
GravityData operator - (const GravityData& o) const {
return GravityData(x-o.x, y-o.y, z-o.z);
}
GravityData operator / (const FPDefault val) const {
return GravityData(x/val, y/val, z/val);
}
std::string asString() const {
std::stringstream ss;
ss << "(" << x << "," << y << "," << z << ")";
return ss.str();
}
bool isValid() const {
return (x == x) && (y == y) && (z == z);
}
bool operator == (const GravityData& o ) const {
return EQ_OR_NAN(x, o.x) &&
EQ_OR_NAN(y, o.y) &&
EQ_OR_NAN(z, o.z);
}
private:
static inline bool EQ_OR_NAN(const FPDefault a, const FPDefault b) {return (a==b) || ( (a!=a) && (b!=b) );}
};
#endif // GRAVITYDATA_H