RBCX
Library for the RB3204-RBCX board with the ESP32 by RoboticsBrno.
Loading...
Searching...
No Matches
RBCXAngle.h
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4
5#ifndef M_PI
6#define M_PI 3.14159265358979323846
7#endif
8
9namespace rb {
10
11class Angle {
12public:
13 typedef float _T;
14 static const Angle Pi;
15
17 : _rads(0) {}
18
19 static Angle rad(_T r) { return Angle(r); }
20 static Angle deg(_T d) { return Angle(d * _T(M_PI / 180)); }
21 static Angle nan() { return Angle(nanf("")); }
22
23 bool isNaN() const { return std::isnan(_rads); }
24
26 _rads += a._rads;
27 return *this;
28 }
30 _rads -= a._rads;
31 return *this;
32 }
33 Angle operator-() const { return Angle(-_rads); }
35 _rads *= c;
36 return *this;
37 }
39 _rads /= c;
40 return *this;
41 }
42
43 _T deg() const { return _rads * _T(180.0 / M_PI); }
44 _T rad() const { return _rads; }
45
46private:
47 _T _rads;
48 Angle(_T r)
49 : _rads(r) {}
50};
51
52Angle operator+(Angle a, Angle b);
53Angle operator-(Angle a, Angle b);
54Angle operator*(Angle a, Angle::_T c);
55Angle operator/(Angle a, Angle::_T c);
56Angle operator"" _deg(long double d);
57Angle operator"" _rad(long double r);
58Angle operator"" _deg(unsigned long long int d);
59Angle operator"" _rad(unsigned long long int r);
60
61}; // namespace rb
#define M_PI
Definition: RBCXAngle.h:6
Definition: RBCXAngle.h:11
Angle & operator+=(Angle a)
Definition: RBCXAngle.h:25
Angle & operator/=(_T c)
Definition: RBCXAngle.h:38
bool isNaN() const
Definition: RBCXAngle.h:23
_T deg() const
Definition: RBCXAngle.h:43
Angle operator-() const
Definition: RBCXAngle.h:33
Angle()
Definition: RBCXAngle.h:16
static const Angle Pi
Definition: RBCXAngle.h:14
static Angle nan()
Definition: RBCXAngle.h:21
_T rad() const
Definition: RBCXAngle.h:44
static Angle rad(_T r)
Definition: RBCXAngle.h:19
Angle & operator*=(_T c)
Definition: RBCXAngle.h:34
float _T
Definition: RBCXAngle.h:13
static Angle deg(_T d)
Definition: RBCXAngle.h:20
Angle & operator-=(Angle a)
Definition: RBCXAngle.h:29
Definition: RBCXAngle.cpp:3
Angle operator*(Angle a, Angle::_T c)
Definition: RBCXAngle.cpp:17
Angle operator-(Angle a, Angle b)
Definition: RBCXAngle.cpp:12
Angle operator/(Angle a, Angle::_T c)
Definition: RBCXAngle.cpp:22
Angle operator+(Angle a, Angle b)
Definition: RBCXAngle.cpp:7