|
mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
|
Go to the documentation of this file.
47 template <
typename flt,
class spec>
73 cyclic(
const spec& other) : val(other.val){};
85 static constexpr flt
minimum = spec::minimum;
86 static constexpr flt
supremum = spec::supremum;
131 const flt wrapped = rem +
minimum + std::signbit(rem) *
range;
157 static flt
unwrap(
const flt what,
const flt from)
159 return from +
diff(what, from);
171 static flt
pdist(
const flt from,
const flt to)
178 const flt tmp = to.val - from.val;
179 const flt
dist = tmp + std::signbit(tmp) *
range;
193 static flt
diff(
const flt minuend,
const flt subtrahend)
200 const flt d = minuend.val - subtrahend.val;
219 static flt
dist(
const flt from,
const flt to)
226 return std::abs(
diff(from, to));
249 const flt dang =
diff(to, from);
250 const flt intp = from.val + coeff * dang;
264 static flt
interp(
const flt from,
const flt to,
const flt coeff)
295 const flt dang =
pdist(to, from);
296 const flt intp = from.val + coeff * dang;
311 static flt
pinterp(
const flt from,
const flt to,
const flt coeff)
333 template <
class other_t>
336 return other_t(what.val /
range * other_t::range);
350 template <
class other_t>
353 return other_t(val /
range * other_t::range);
399 val =
wrap(val + other.val);
411 val =
diff(val, other.val);
424 return wrap(lhs.val + rhs.val);
436 return diff(lhs, rhs);
452 template <
typename flt,
class spec>
467 template <
typename flt,
class spec>
480 template <
typename flt,
class spec>
483 return (out << ang.
value());
492 static constexpr
double minimum = 0;
493 static constexpr
double supremum = 2 * M_PI;
502 static constexpr
double minimum = -M_PI;
503 static constexpr
double supremum = M_PI;
512 static constexpr
double minimum = 0;
513 static constexpr
double supremum = 360;
522 static constexpr
double minimum = -180;
523 static constexpr
double supremum = 180;
flt value() const
Getter for val.
Definition: cyclic.h:80
static flt pdist(const flt from, const flt to)
Returns length of the shortest walk in the positive direction from the first parameter to the second ...
Definition: cyclic.h:171
Convenience specialization of the cyclic class for signed degrees (from $-180$ to $180$).
Definition: cyclic.h:519
cyclic & operator=(const flt nval)
Assignment operator.
Definition: cyclic.h:363
cyclic()
Default constructor.
Definition: cyclic.h:55
bool operator<(const cyclic< flt, spec > &lhs, const cyclic< flt, spec > &rhs)
Implementation of the comparison operation between two angles.
Definition: cyclic.h:453
std::ostream & operator<<(std::ostream &out, const cyclic< flt, spec > &ang)
Implementation of the stream output operator.
Definition: cyclic.h:481
static flt interpUnwrapped(const flt from, const flt to, const flt coeff)
Interpolation between two circular quantities without wrapping of the result.
Definition: cyclic.h:242
friend spec operator+(const cyclic &lhs, const cyclic &rhs)
Addition operator.
Definition: cyclic.h:422
static flt diff(const flt minuend, const flt subtrahend)
Returns the difference between the two circular values.
Definition: cyclic.h:193
static flt dist(const flt from, const flt to)
Returns the distance between the two circular values.
Definition: cyclic.h:219
Convenience specialization of the cyclic class for unsigned degrees (from $0$ to $360$).
Definition: cyclic.h:509
cyclic(const cyclic &other)
Copy constructor.
Definition: cyclic.h:67
Implementation of the a general cyclic value (such as angles in radians/degrees etc).
Definition: cyclic.h:48
Convenience specialization of the cyclic class for unsigned radians (from $0$ to $2\pi$).
Definition: cyclic.h:489
Convenience specialization of the cyclic class for signed radians (from $-\pi$ to $\pi$).
Definition: cyclic.h:499
cyclic(const spec &other)
Copy constructor.
Definition: cyclic.h:73
bool operator>(const cyclic< flt, spec > &lhs, const cyclic< flt, spec > &rhs)
Implementation of the comparison operation between two angles.
Definition: cyclic.h:468
static bool inRange(const flt val)
Checks if val is within the valid interval of wrapped values.
Definition: cyclic.h:100
static flt unwrap(const flt what, const flt from)
Returns value of the parameter what modified so that there is no "jump" between from and \t what.
Definition: cyclic.h:157
static constexpr flt supremum
Supremum of the valid interval of wrapped values .
Definition: cyclic.h:86
static constexpr flt half_range
Half of the range of the valid interval of wrapped values (used for some calculations).
Definition: cyclic.h:89
static constexpr flt minimum
Minimum of the valid interval of wrapped values .
Definition: cyclic.h:85
cyclic & operator=(const cyclic &other)
Assignment operator.
Definition: cyclic.h:374
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition: attitude_converter.h:29
cyclic(const flt val)
Constructor overload.
Definition: cyclic.h:61
friend flt operator-(const cyclic &lhs, const cyclic &rhs)
Subtraction operator (uses the diff() method).
Definition: cyclic.h:434
other_t convert() const
Conversion between two different circular quantities.
Definition: cyclic.h:351
cyclic & operator=(cyclic &&other)
Move operator.
Definition: cyclic.h:385
static flt pinterp(const flt from, const flt to, const flt coeff)
Interpolation between two circular quantities in the positive direction.
Definition: cyclic.h:311
cyclic & operator+=(const cyclic &other)
Addition compound operator.
Definition: cyclic.h:397
static flt interp(const flt from, const flt to, const flt coeff)
Interpolation between two circular quantities.
Definition: cyclic.h:264
cyclic & operator-=(const cyclic &other)
Subtraction compound operator.
Definition: cyclic.h:409
static flt pinterpUnwrapped(const flt from, const flt to, const flt coeff)
Interpolation between two circular quantities in the positive direction without wrapping of the resul...
Definition: cyclic.h:288
static flt wrap(const flt val)
Returns val, converted to the valid interval of values.
Definition: cyclic.h:114
static constexpr flt range
Range of the valid interval of wrapped values (also the period of the cyclic quantity).
Definition: cyclic.h:87
static other_t convert(const cyclic &what)
Conversion between two different circular quantities.
Definition: cyclic.h:334