2020-11-27 05:10:47 -05:00
|
|
|
#pragma once
|
2015-08-01 14:36:28 -04:00
|
|
|
//
|
|
|
|
// FILE: Angle.h
|
2021-10-17 16:24:38 -04:00
|
|
|
// AUTHOR: Rob Tillaart
|
2023-01-31 09:29:30 -05:00
|
|
|
// VERSION: 0.1.14
|
2015-08-01 14:36:28 -04:00
|
|
|
// PURPOSE: angle library for Arduino
|
2023-01-31 09:29:30 -05:00
|
|
|
// URL: https://github.com/RobTillaart/Angle
|
|
|
|
// http://forum.arduino.cc/index.php?topic=339402
|
2015-08-01 14:36:28 -04:00
|
|
|
//
|
2015-08-03 07:42:59 -04:00
|
|
|
// AngleFormat proxy added 03/03/15 by Christoper Andrews.
|
|
|
|
//
|
2015-08-01 14:36:28 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2020-11-27 05:10:47 -05:00
|
|
|
#include "math.h"
|
2015-08-01 14:36:28 -04:00
|
|
|
#include "Arduino.h"
|
|
|
|
#include "Printable.h"
|
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2023-01-31 09:29:30 -05:00
|
|
|
#define ANGLE_LIB_VERSION (F("0.1.14"))
|
2021-01-29 06:31:58 -05:00
|
|
|
|
2015-08-01 14:36:28 -04:00
|
|
|
|
2015-08-03 07:42:59 -04:00
|
|
|
class Angle;
|
|
|
|
|
|
|
|
enum AngleFormatMode{
|
|
|
|
D = 1, M, S, T
|
|
|
|
};
|
|
|
|
|
2021-12-13 07:48:16 -05:00
|
|
|
|
2015-08-03 07:42:59 -04:00
|
|
|
struct AngleFormat : Printable{
|
|
|
|
|
|
|
|
AngleFormat( const Angle &ref, AngleFormatMode format );
|
|
|
|
size_t printTo(Print& p) const;
|
2015-08-23 12:20:08 -04:00
|
|
|
|
2015-08-03 07:42:59 -04:00
|
|
|
const Angle ∠
|
|
|
|
AngleFormatMode mode;
|
|
|
|
};
|
|
|
|
|
2021-12-13 07:48:16 -05:00
|
|
|
|
2015-08-01 14:36:28 -04:00
|
|
|
class Angle: public Printable
|
|
|
|
{
|
|
|
|
public:
|
2021-12-13 07:48:16 -05:00
|
|
|
Angle(int dd = 0, int mm = 0, int ss = 0, int tt = 0);
|
2015-08-01 14:36:28 -04:00
|
|
|
Angle(double alpha);
|
2021-12-13 07:48:16 -05:00
|
|
|
Angle(const char * str);
|
2015-08-01 14:44:45 -04:00
|
|
|
|
2021-01-29 06:31:58 -05:00
|
|
|
int sign() { return neg ? -1 : 1; };
|
|
|
|
int degree() { return d; };
|
|
|
|
int minute() { return m; };
|
|
|
|
int second() { return s; };
|
2015-08-23 12:20:08 -04:00
|
|
|
int tenthousand() { return t; };
|
2015-08-01 14:36:28 -04:00
|
|
|
|
2015-08-03 07:42:59 -04:00
|
|
|
size_t printTo(Print& p) const { return printTo( p, T ); }
|
|
|
|
size_t printTo(Print& p, AngleFormatMode mode) const;
|
2015-08-23 12:20:08 -04:00
|
|
|
|
2015-08-03 07:42:59 -04:00
|
|
|
AngleFormat format( AngleFormatMode format ) { return AngleFormat( *this, format ); }
|
2015-08-23 12:20:08 -04:00
|
|
|
|
2015-08-01 14:36:28 -04:00
|
|
|
double toDouble();
|
2015-08-02 07:38:56 -04:00
|
|
|
double toRadians() { return toDouble() * PI / 180.0; };
|
2015-08-23 12:20:08 -04:00
|
|
|
void fromRadians(double rad) { *this = rad * 180.0/PI; };
|
2015-08-01 14:36:28 -04:00
|
|
|
|
2022-10-29 06:45:36 -04:00
|
|
|
// EQUALITIES
|
2015-08-01 14:36:28 -04:00
|
|
|
bool operator == (const Angle& a) { return compare(*this, a) == 0; };
|
|
|
|
bool operator != (const Angle& a) { return compare(*this, a) != 0; };
|
|
|
|
bool operator < (const Angle& a) { return compare(*this, a) < 0; };
|
|
|
|
bool operator <= (const Angle& a) { return compare(*this, a) <= 0; };
|
|
|
|
bool operator > (const Angle& a) { return compare(*this, a) > 0; };
|
|
|
|
bool operator >= (const Angle& a) { return compare(*this, a) >= 0; };
|
|
|
|
|
2022-10-29 06:45:36 -04:00
|
|
|
// NEGATE
|
2015-10-19 14:15:06 -04:00
|
|
|
Angle operator - ();
|
2015-08-01 14:36:28 -04:00
|
|
|
|
|
|
|
Angle operator + (const Angle&);
|
|
|
|
Angle& operator += (const Angle&);
|
2015-08-01 14:44:45 -04:00
|
|
|
|
2015-08-01 14:36:28 -04:00
|
|
|
Angle operator - (const Angle&);
|
|
|
|
Angle& operator -= (const Angle&);
|
|
|
|
|
|
|
|
Angle operator * (const double);
|
|
|
|
Angle& operator *= (const double);
|
|
|
|
|
|
|
|
Angle operator / (const double);
|
|
|
|
Angle& operator /= (const double);
|
|
|
|
|
2022-10-29 06:45:36 -04:00
|
|
|
double operator / (Angle&); // ratio
|
2015-08-01 14:36:28 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
void normalize();
|
|
|
|
int compare(const Angle&, const Angle&);
|
|
|
|
|
2015-08-01 14:44:45 -04:00
|
|
|
Angle addHelper(const Angle &a);
|
|
|
|
Angle subHelper(const Angle &a);
|
|
|
|
|
2022-10-29 06:45:36 -04:00
|
|
|
bool neg; // angle is negative
|
|
|
|
int d; // whole degrees
|
|
|
|
int m; // minutes
|
|
|
|
int s; // seconds
|
|
|
|
int t; // ten thousands
|
2015-08-01 14:36:28 -04:00
|
|
|
};
|
2020-11-27 05:10:47 -05:00
|
|
|
|
2021-12-13 07:48:16 -05:00
|
|
|
|
2023-01-31 09:29:30 -05:00
|
|
|
// -- END OF FILE
|
2021-12-13 07:48:16 -05:00
|
|
|
|