Skip to content

Commit

Permalink
Fix #4, use **degrees** as internal format (#5)
Browse files Browse the repository at this point in the history
- Fix #4, use **degrees** as internal format to improve precision (a bit)
- set internal size to **double** for those board that support 8 bytes double.
- improved **AngleConverter_demo.ino**
  • Loading branch information
RobTillaart authored Jan 15, 2024
1 parent d739394 commit 393afc5
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 133 deletions.
94 changes: 47 additions & 47 deletions AngleConvertor.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//
// FILE: AngleConvertor.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.2
// VERSION: 0.2.0
// DATE: 2022-12-01
// PURPOSE: Angle conversion class
// URL: https://github.com/RobTillaart/AngleConvertor
Expand All @@ -11,7 +11,7 @@
#include "Arduino.h"


#define ANGLECONVERTOR_LIB_VERSION (F("0.1.2"))
#define ANGLECONVERTOR_LIB_VERSION (F("0.2.0"))


/////////////////////////////////////////////////////////////
Expand All @@ -24,68 +24,68 @@ class AngleConvertor
AngleConvertor() { _v = 0; };

// SETTERS
void setDegrees(float value = 0) { _v = value * (M_PI / 180.0); };
void setRadians(float value = 0) { _v = value; };
void setGradians(float value = 0) { _v = value * (M_PI / 200.0); };
void setAngularMil(float value = 0) { _v = value * (M_PI / 3200.0); };
void setBinaryRadians(float value = 0) { _v = value * (M_PI / 128.0); };
void setCentiTurn(float value = 0) { _v = value * (M_PI / 50.0); };
void setDiameterPart(float value = 0) { _v = value * (M_PI / 60.0); };
void setHexacontade(float value = 0) { _v = value * (M_PI / 30.0); };
void setHourAngle(float value = 0) { _v = value * (M_PI / 12.0); };
void setMilliTurn(float value = 0) { _v = value * (M_PI / 500.0); };

void setMinuteTime(float value = 0) { _v = value * (M_PI / 720.0); };
void setOctant(float value = 0) { _v = value * (M_PI / 4.0); };
void setPechus(float value = 0) { _v = value * (M_PI / 90.0); }; // assumes 2°
void setPoints(float value = 0) { _v = value * (M_PI / 16.0); };
void setQuadrant(float value = 0) { _v = value * (M_PI / 2.0); };
void setQuarterPoint(float value = 0) { _v = value * (M_PI / 64.0); };
void setSecondsTime(float value = 0) { _v = value * (M_PI / 43200); };
void setSextant(float value = 0) { _v = value * (M_PI / 3.0); };
void setSign(float value = 0) { _v = value * (M_PI / 6.0); };
void setTurn(float value = 0) { _v = value * (M_PI / 0.5); };
void setDegrees(double value = 0) { _v = value * (180.0 / 180.0); };
void setRadians(double value = 0) { _v = value * (180.0 / M_PI); };
void setGradians(double value = 0) { _v = value * (180.0 / 200.0); };
void setAngularMil(double value = 0) { _v = value * (180.0 / 3200.0); };
void setBinaryRadians(double value = 0) { _v = value * (180.0 / 128.0); };
void setCentiTurn(double value = 0) { _v = value * (180.0 / 50.0); };
void setDiameterPart(double value = 0) { _v = value * (180.0 / 60.0); };
void setHexacontade(double value = 0) { _v = value * (180.0 / 30.0); };
void setHourAngle(double value = 0) { _v = value * (180.0 / 12.0); };
void setMilliTurn(double value = 0) { _v = value * (180.0 / 500.0); };

void setMinuteTime(double value = 0) { _v = value * (180.0 / 720.0); };
void setOctant(double value = 0) { _v = value * (180.0 / 4.0); };
void setPechus(double value = 0) { _v = value * (180.0 / 90.0); }; // assumes 2°
void setPoints(double value = 0) { _v = value * (180.0 / 16.0); };
void setQuadrant(double value = 0) { _v = value * (180.0 / 2.0); };
void setQuarterPoint(double value = 0) { _v = value * (180.0 / 64.0); };
void setSecondsTime(double value = 0) { _v = value * (180.0 / 43200); };
void setSextant(double value = 0) { _v = value * (180.0 / 3.0); };
void setSign(double value = 0) { _v = value * (180.0 / 6.0); };
void setTurn(double value = 0) { _v = value * (180.0 / 0.5); };


// GETTERS
float getDegrees() { return _v * (180.0 / M_PI); };
float getRadians() { return _v; };
float getGradians() { return _v * (200.0 / M_PI); };
float getAngularMil() { return _v * (3200.0 / M_PI); };
float getBinaryRadians() { return _v * (128.0 / M_PI); };
float getCentiTurn() { return _v * (50.0 / M_PI); };
float getDiameterPart() { return _v * (60.0 / M_PI); };
float getHexacontade() { return _v * (30.0 / M_PI); };
float getHourAngle() { return _v * (12.0 / M_PI); };
float getMilliTurn() { return _v * (500.0 / M_PI); };

float getMinuteTime() { return _v * (720.0 / M_PI); };
float getOctant() { return _v * (4.0 / M_PI); };
float getPechus() { return _v * (90.0 / M_PI); }; // assumes 2°
float getPoints() { return _v * (16.0 / M_PI); };
float getQuadrant() { return _v * (2.0 / M_PI); };
float getQuarterPoint() { return _v * (64.0 / M_PI); };
float getSecondsTime() { return _v * (43200 / M_PI); };
float getSextant() { return _v * (3.0 / M_PI); };
float getSign() { return _v * (6.0 / M_PI); };
float getTurn() { return _v * (0.5 / M_PI); };
double getDegrees() { return _v * (180.0 / 180.0); };
double getRadians() { return _v * (M_PI / 180.0); };
double getGradians() { return _v * (200.0 / 180.0); };
double getAngularMil() { return _v * (3200.0 / 180.0); };
double getBinaryRadians() { return _v * (128.0 / 180.0); };
double getCentiTurn() { return _v * (50.0 / 180.0); };
double getDiameterPart() { return _v * (60.0 / 180.0); };
double getHexacontade() { return _v * (30.0 / 180.0); };
double getHourAngle() { return _v * (12.0 / 180.0); };
double getMilliTurn() { return _v * (500.0 / 180.0); };

double getMinuteTime() { return _v * (720.0 / 180.0); };
double getOctant() { return _v * (4.0 / 180.0); };
double getPechus() { return _v * (90.0 / 180.0); }; // assumes 2°
double getPoints() { return _v * (16.0 / 180.0); };
double getQuadrant() { return _v * (2.0 / 180.0); };
double getQuarterPoint() { return _v * (64.0 / 180.0); };
double getSecondsTime() { return _v * (43200 / 180.0); };
double getSextant() { return _v * (3.0 / 180.0); };
double getSign() { return _v * (6.0 / 180.0); };
double getTurn() { return _v * (0.5 / 180.0); };


// WINDROSE
//
char * windrose()
{
return windrose(_v * (180.0 / M_PI));
return windrose(_v);
}

char * windrose(float degrees)
char * windrose(double degrees)
{
uint8_t idx = (degrees + 11.25) * 0.044444444444444; // 1.0 / 22.5
return _wr2[idx];
}

private:
float _v; // internal use radians.
double _v; // internal use degrees (0.2.0).
char _wr2[17][4] = {
"N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW", "N"};

Expand Down
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ and this project adheres to [Semantic Versioning](http://semver.org/).



## [0.2.0] - 2024-01-15
- Fix #4, use **degrees** as internal format to improve precision (a bit)
- set internal size to **double** for those board that support 8 bytes double.
- improved **AngleConverter_demo.ino**

----

## [0.1.2] - 2023-10-17
- update readme.md


## [0.1.1] - 2023-01-23
- update GitHub actions
- update license 2023
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022-2023 Rob Tillaart
Copyright (c) 2022-2024 Rob Tillaart

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
89 changes: 47 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ Arduino library for converting angles (degrees/radians) to less known formats.

AngleConvertor is an Arduino class to convert an angle from and to less known formats.

Since 0.2.0 the class uses degrees as internal format as that improved precision a bit
compared to the pre-0.2.0 version that used radians.
Furthermore to improve precision the class uses doubles, so platforms that support these
can gain extra precision.


#### Formats

Expand Down Expand Up @@ -68,61 +73,61 @@ AngleConvertor is an Arduino class to convert an angle from and to less known fo

#### Setters

- **void setDegrees(float value = 0)**
- **void setRadians(float value = 0)**
- **void setGradians(float value = 0)**
- **void setAngularMil(float value = 0)**
- **void setBinaryRadians(float value = 0)**
- **void setCentiTurn(float value = 0)**
- **void setDiameterPart(float value = 0)**
- **void setHexacontade(float value = 0)**
- **void setHourAngle(float value = 0)**
- **void setMilliTurn(float value = 0)**
- **void setMinuteTime(float value = 0)**
- **void setOctant(float value = 0)**
- **void setPechus(float value = 0)**
- **void setPoints(float value = 0)**
- **void setQuadrant(float value = 0)**
- **void setQuarterPoint(float value = 0)**
- **void setSecondsTime(float value = 0)**
- **void setSextant(float value = 0)**
- **void setSign(float value = 0)**
- **void setTurn(float value = 0)**
- **void setDegrees(double value = 0)**
- **void setRadians(double value = 0)**
- **void setGradians(double value = 0)**
- **void setAngularMil(double value = 0)**
- **void setBinaryRadians(double value = 0)**
- **void setCentiTurn(double value = 0)**
- **void setDiameterPart(double value = 0)**
- **void setHexacontade(double value = 0)**
- **void setHourAngle(double value = 0)**
- **void setMilliTurn(double value = 0)**
- **void setMinuteTime(double value = 0)**
- **void setOctant(double value = 0)**
- **void setPechus(double value = 0)**
- **void setPoints(double value = 0)**
- **void setQuadrant(double value = 0)**
- **void setQuarterPoint(double value = 0)**
- **void setSecondsTime(double value = 0)**
- **void setSextant(double value = 0)**
- **void setSign(double value = 0)**
- **void setTurn(double value = 0)**


#### Getters

- **float getDegrees()**
- **float getRadians()**
- **float getGradians()**
- **float getAngularMil()**
- **float getBinaryRadians()**
- **float getCentiTurn()**
- **float getDiameterPart()**
- **float getHexacontade()**
- **float getHourAngle()**
- **float getMilliTurn()**
- **float getMinuteTime()**
- **float getOctant()**
- **float getPechus()**
- **float getPoints()**
- **float getQuadrant()**
- **float getQuarterPoint()**
- **float getSecondsTime()**
- **float getSextant()**
- **float getSign()**
- **float getTurn()**
- **double getDegrees()**
- **double getRadians()**
- **double getGradians()**
- **double getAngularMil()**
- **double getBinaryRadians()**
- **double getCentiTurn()**
- **double getDiameterPart()**
- **double getHexacontade()**
- **double getHourAngle()**
- **double getMilliTurn()**
- **double getMinuteTime()**
- **double getOctant()**
- **double getPechus()**
- **double getPoints()**
- **double getQuadrant()**
- **double getQuarterPoint()**
- **double getSecondsTime()**
- **double getSextant()**
- **double getSign()**
- **double getTurn()**

#### WindRose

#### WindRose

From: https://forum.arduino.cc/t/function-optimization-wind-direction-open-for-ideas/92493/10

Converts an angle in degrees to a char array like "WSW".
0 and 360 degrees is considered North.

- **char \* windrose()** converter version.
- **char \* windrose(float degrees)** stand alone version.
- **char \* windrose(double degrees)** stand alone version.
degrees should be between 0 and 360, as function does no normalization.


Expand Down
Loading

0 comments on commit 393afc5

Please sign in to comment.