132 lines
3.7 KiB
Markdown
Raw Normal View History

2021-01-29 12:31:58 +01:00
[![Arduino CI](https://github.com/RobTillaart/Angle/workflows/Arduino%20CI/badge.svg)](https://github.com/marketplace/actions/arduino_ci)
2021-10-17 22:24:38 +02:00
[![Arduino-lint](https://github.com/RobTillaart/Angle/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/RobTillaart/Angle/actions/workflows/arduino-lint.yml)
[![JSON check](https://github.com/RobTillaart/Angle/actions/workflows/jsoncheck.yml/badge.svg)](https://github.com/RobTillaart/Angle/actions/workflows/jsoncheck.yml)
2023-10-17 15:08:05 +02:00
[![GitHub issues](https://img.shields.io/github/issues/RobTillaart/Angle.svg)](https://github.com/RobTillaart/Angle/issues)
2021-01-29 12:31:58 +01:00
[![License: MIT](https://img.shields.io/badge/license-MIT-green.svg)](https://github.com/RobTillaart/Angle/blob/master/LICENSE)
[![GitHub release](https://img.shields.io/github/release/RobTillaart/Angle.svg?maxAge=3600)](https://github.com/RobTillaart/Angle/releases)
2023-10-17 15:08:05 +02:00
[![PlatformIO Registry](https://badges.registry.platformio.org/packages/robtillaart/library/Angle.svg)](https://registry.platformio.org/libraries/robtillaart/Angle)
2021-01-29 12:31:58 +01:00
2020-11-27 11:10:47 +01:00
# Angle
2021-10-17 22:24:38 +02:00
Arduino library for basic math for Angles in degrees, minute, seconds and ten-thousands.
2021-01-29 12:31:58 +01:00
2020-11-27 11:10:47 +01:00
## Description
2021-10-17 22:24:38 +02:00
Angle is an Arduino class to print, compare and do basic maths with angles
in degrees, minutes seconds and ten-thousands. The class was created to be
2020-11-27 11:10:47 +01:00
able to print an angle with minutes and seconds instead of as a floating point
or radians.
2021-10-17 22:24:38 +02:00
To make the library more useful basic maths ( + - \* / )
2021-01-29 12:31:58 +01:00
and comparisons ( == != < <= > >= ) are added to the class.
The library implements the Printable interface, allowing one to call
2021-12-13 13:48:16 +01:00
**Serial.println(angle)** or **SD.print(angle)**.
2021-01-29 12:31:58 +01:00
2023-01-31 15:29:30 +01:00
Degree sign ° = ALT-0176 (Windows)
#### Related
- https://github.com/RobTillaart/AngleConvertor
- https://github.com/RobTillaart/AverageAngle
- https://github.com/RobTillaart/Angle
- https://github.com/RobTillaart/runningAngle
2021-01-29 12:31:58 +01:00
## Interface
2023-01-31 15:29:30 +01:00
```cpp
#include "Angle.h"
```
#### Constructors
2021-01-29 12:31:58 +01:00
2021-12-13 13:48:16 +01:00
- **Angle(int dd = 0, int mm = 0, int ss = 0, int tt = 0)** create an Angle, default is zero.
2021-01-29 12:31:58 +01:00
- **Angle(double alpha)** create an Angle from a double.
2021-10-17 22:24:38 +02:00
- **Angle(char \* str)** create an Angle from a string e.g. "45.31234".
2021-01-29 12:31:58 +01:00
2023-01-31 15:29:30 +01:00
#### Base
2021-01-29 12:31:58 +01:00
2021-12-13 13:48:16 +01:00
- **int sign()** returns -1 or 1.
- **int degree()** returns # degrees.
- **int minute()** returns # minutes.
- **int second()** returns # seconds.
- **int tenthousand()** returns # ten-thousands of a second.
2021-01-29 12:31:58 +01:00
2023-01-31 15:29:30 +01:00
#### Conversions
2021-01-29 12:31:58 +01:00
2021-12-13 13:48:16 +01:00
- **double toDouble()** returns the angle as a double (0..360.0, float on UNO).
- **double toRadians()** returns the angle in radians (0..TWO_PI).
2021-10-17 22:24:38 +02:00
- **void fromRadian(double rad)** create an angle from radians.
2021-01-29 12:31:58 +01:00
2023-01-31 15:29:30 +01:00
More conversions - https://github.com/RobTillaart/AngleConvertor
2021-01-29 12:31:58 +01:00
2023-01-31 15:29:30 +01:00
#### Equality operators
2021-01-29 12:31:58 +01:00
2021-12-13 13:48:16 +01:00
The library supports equality operator "==", "!=", "<" "<=" ">" and ">=" .
2021-01-29 12:31:58 +01:00
2023-01-31 15:29:30 +01:00
#### Math operators
2021-01-29 12:31:58 +01:00
2021-12-13 13:48:16 +01:00
- **negate** returns -angle.
- **addition** and **subtract** add angles to angles.
- **multiplication** and **division** multiply an angle with a double.
- **ratio** ratio = Angle/Angle.
2021-01-29 12:31:58 +01:00
2020-11-27 11:10:47 +01:00
## Operation
2021-12-13 13:48:16 +01:00
See examples.
2020-11-27 11:10:47 +01:00
## Note
2021-01-29 12:31:58 +01:00
2023-01-31 15:29:30 +01:00
The library has not been tested extensively and it could still contain bugs.
Especially the constructor does not check input so use it carefully.
2021-12-13 13:48:16 +01:00
## Future
2023-01-31 15:29:30 +01:00
#### Must
2021-12-13 13:48:16 +01:00
- improve documentation
2023-01-31 15:29:30 +01:00
#### Should
- Test normalize code
- unit tests, sketch?
- test more
- TOCHECK in code
2022-10-29 12:45:36 +02:00
- improve code quality
- use better variable names in code
2023-01-31 15:29:30 +01:00
#### Could
- optimize code where possible
- low priority
- move all code to .cpp
- change output format to confirm standard 4°12'14.1234"
#### Wont
2021-12-13 13:48:16 +01:00
2023-10-17 15:08:05 +02:00
## Support
If you appreciate my libraries, you can support the development and maintenance.
Improve the quality of the libraries by providing issues and Pull Requests, or
donate through PayPal or GitHub sponsors.
Thank you,