Angle
Arduino library for basic math for Angles in degrees, minute, seconds
Install / Use
/learn @RobTillaart/AngleREADME
Angle
Arduino library for basic math for Angles in degrees, minute, seconds and ten-thousands.
Description
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 able to print an angle with minutes and seconds instead of as a floating point or radians.
To make the library more useful basic maths ( + - * / ) and comparisons ( == != < <= > >= ) are added to the class.
The library implements the Printable interface, allowing one to call
Serial.println(angle) or SD.print(angle).
Degree sign ° = ALT-0176 (Windows)
Warning
The library has not been tested extensively and it could still contain bugs. Especially the constructor does not check input so use it with care.
As always feedback is welcome
Related
- https://github.com/RobTillaart/Angle
- https://github.com/RobTillaart/AngleConvertor - convert to other formats
- https://github.com/RobTillaart/AverageAngle
- https://github.com/RobTillaart/runningAngle
- https://github.com/RobTillaart/AS5600 - magnetic angle measurements
For printing floats in scientific or engineering format
https://github.com/RobTillaart/printHelpers
Interface
#include "Angle.h"
Constructors
- Angle(int dd = 0, int mm = 0, int ss = 0, int tt = 0) create an Angle, default is zero.
- dd = degrees, mm = minutes, ss = seconds, tt = ten-thousands of a second.
- Angle(double alpha) create an Angle from a double, unit is degrees.
- Angle(char * str) create an Angle from a string e.g. "45.31234".
Base
- bool isZero() returns true if angle is 0.
- int sign() returns -1 or 1. Zero degrees will return 1.
- int degree() returns # degrees.
- int minute() returns # minutes.
- int second() returns # seconds.
- int tenthousand() returns # ten-thousands of a second.
Conversions
- double toDouble() returns the angle as a double (0..360.0, float on UNO).
- double toRadians() returns the angle in radians (0..TWO_PI).
- void fromRadian(double rad) create an angle from radians.
For more conversions check - https://github.com/RobTillaart/AngleConvertor
Equality operators
The library supports equality operator "==", "!=", "<" "<=" ">" and ">=" .
Math operators
The library supports:
- negate returns -angle.
- addition and subtract add angles to angles.
- multiplication and division multiply an angle with a double.
- ratio ratio = Angle/Angle.
Future
Must
- improve documentation
Should
- Test normalize code
- unit tests, sketch?
- test more
- TOCHECK in code
- improve code quality
Could
- optimize code where possible
- remove modulos if possible
- change output format to confirm standard 4°12'14.1234"
Wont
- move all code to .cpp
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,
Related Skills
node-connect
352.9kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
111.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
352.9kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
352.9kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
