mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.2 ellipse
This commit is contained in:
parent
6e0708dbcc
commit
f7ee3db64c
@ -1,3 +1,18 @@
|
||||
platforms:
|
||||
rpipico:
|
||||
board: rp2040:rp2040:rpipico
|
||||
package: rp2040:rp2040
|
||||
gcc:
|
||||
features:
|
||||
defines:
|
||||
- ARDUINO_ARCH_RP2040
|
||||
warnings:
|
||||
flags:
|
||||
|
||||
packages:
|
||||
rp2040:rp2040:
|
||||
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
|
||||
|
||||
compile:
|
||||
# Choosing to run compilation tests on 2 different Arduino platforms
|
||||
platforms:
|
||||
@ -8,4 +23,6 @@ compile:
|
||||
- m4
|
||||
- esp32
|
||||
# - esp8266
|
||||
# - mega2560
|
||||
# - mega2560
|
||||
- rpipico
|
||||
|
||||
|
23
libraries/ellipse/CHANGELOG.md
Normal file
23
libraries/ellipse/CHANGELOG.md
Normal file
@ -0,0 +1,23 @@
|
||||
# Change Log ellipse
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.1.2] - 2022-11-02
|
||||
- add changelog.md
|
||||
- add rp2040 to build-CI
|
||||
- update readme.md
|
||||
- refactor code
|
||||
- add getLongRadius() and getShortRadius()
|
||||
|
||||
|
||||
## [0.1.1] - 2022-07-24
|
||||
- add angle() + example
|
||||
- add isCircle(), isFlat()
|
||||
- update readme.md
|
||||
|
||||
## [0.1.0] - 2021-10-31
|
||||
- initial version
|
@ -67,9 +67,6 @@ See examples.
|
||||
- make other code symmetric.
|
||||
- additional functions
|
||||
- Bresenham to draw ellipse?
|
||||
- **float getLongRadius()**
|
||||
- **float getShortRadius()**
|
||||
- move all code to .cpp
|
||||
- documentation
|
||||
- refer Wikipedia.
|
||||
|
||||
|
@ -2,16 +2,12 @@
|
||||
// FILE: ellipse.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-10-31
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.1.2
|
||||
// PURPOSE: Arduino library for ellipse maths
|
||||
// URL: https://github.com/RobTillaart/ellipse
|
||||
// TRIGGER: https://www.youtube.com/watch?v=5nW3nJhBHL0
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.0 2021-10-31 initial version
|
||||
// 0.1.1 2022-07- add angle() + example
|
||||
// add isCircle(), isFlat()
|
||||
// update readme.md
|
||||
// HISTORY: see changelog.md
|
||||
|
||||
|
||||
#include "ellipse.h"
|
||||
@ -26,8 +22,8 @@ ellipse::ellipse(float a, float b)
|
||||
|
||||
//////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// unknown - see youtube link.
|
||||
// p = 2 * PI * sqrt((a*a + b*b)/2);
|
||||
// unknown - see youtube link.
|
||||
// p = 2 * PI * sqrt((a*a + b*b)/2);
|
||||
//
|
||||
float ellipse::circumference()
|
||||
{
|
||||
@ -43,7 +39,7 @@ float ellipse::perimeter_ref()
|
||||
|
||||
float ellipse::perimeter_Keppler()
|
||||
{
|
||||
// Keppler
|
||||
// Keppler
|
||||
float p = 2 * PI * (_a + _b) / 2; // very fast for a ~ b
|
||||
return p;
|
||||
}
|
||||
@ -51,8 +47,8 @@ float ellipse::perimeter_Keppler()
|
||||
|
||||
float ellipse::perimeter_Ramanujan1()
|
||||
{
|
||||
// Srinivasa Ramanujan I - very good
|
||||
// float p = PI * (3 * (_a + _b) - sqrt((3 * _a +_b)*(_a + 3 * _b)));
|
||||
// Srinivasa Ramanujan I - very good
|
||||
// float p = PI * (3 * (_a + _b) - sqrt((3 * _a +_b)*(_a + 3 * _b)));
|
||||
float a3 = 3 * _a;
|
||||
float b3 = 3 * _b;
|
||||
float p = PI * (a3 + b3 - sqrt( (a3 + _b)*(_a + b3)));
|
||||
@ -63,7 +59,7 @@ float ellipse::perimeter_Ramanujan1()
|
||||
|
||||
float ellipse::perimeter_Ramanujan2()
|
||||
{
|
||||
// Srinivasa Ramanujan II - extremely good
|
||||
// Srinivasa Ramanujan II - extremely good
|
||||
float x = _a - _b;
|
||||
float y = _a + _b;
|
||||
float h3 = 3 * (x * x) / (y * y);
|
||||
@ -104,6 +100,30 @@ bool ellipse::isFlat()
|
||||
}
|
||||
|
||||
|
||||
void ellipse::setA(float a)
|
||||
{
|
||||
_a = abs(a);
|
||||
}
|
||||
|
||||
|
||||
void ellipse::setB(float b)
|
||||
{
|
||||
_b = abs(b);
|
||||
};
|
||||
|
||||
|
||||
float ellipse::getA()
|
||||
{
|
||||
return _a;
|
||||
}
|
||||
|
||||
|
||||
float ellipse::getB()
|
||||
{
|
||||
return _b;
|
||||
}
|
||||
|
||||
|
||||
float ellipse::getC()
|
||||
{
|
||||
float e = eccentricity();
|
||||
@ -112,11 +132,26 @@ float ellipse::getC()
|
||||
}
|
||||
|
||||
|
||||
float ellipse::getLongRadius()
|
||||
{
|
||||
if (_a >= _b) return _a;
|
||||
return _b;
|
||||
}
|
||||
|
||||
|
||||
float ellipse::getShortRadius()
|
||||
{
|
||||
if (_a >= _b) return _b;
|
||||
return _a;
|
||||
}
|
||||
|
||||
|
||||
float ellipse::angle()
|
||||
{
|
||||
float c = (_b < _a) ? _b/_a : _a/_b;
|
||||
return acos(c) * (180 / PI);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -3,7 +3,7 @@
|
||||
// FILE: ellipse.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-10-31
|
||||
// VERSION: 0.1.1
|
||||
// VERSION: 0.1.2
|
||||
// PURPOSE: Arduino library for ellipse maths
|
||||
// URL: https://github.com/RobTillaart/ellipse
|
||||
//
|
||||
@ -11,31 +11,36 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
#define ELLIPSE_LIB_VERSION (F("0.1.1"))
|
||||
#define ELLIPSE_LIB_VERSION (F("0.1.2"))
|
||||
|
||||
|
||||
class ellipse
|
||||
{
|
||||
public:
|
||||
ellipse(float a, float b); // a >= b
|
||||
ellipse(float a, float b); // a >= b
|
||||
float area();
|
||||
float circumference(); // good algorithm,
|
||||
float perimeter_ref(); // pretty slow but very good over long range
|
||||
float circumference(); // good algorithm,
|
||||
float perimeter_ref(); // pretty slow but very good over long range
|
||||
float perimeter_Keppler();
|
||||
float perimeter_Ramanujan1();
|
||||
float perimeter_Ramanujan2();
|
||||
|
||||
float eccentricity();
|
||||
|
||||
|
||||
// convenience functions.
|
||||
bool isCircle(float epsilon = 0.0);
|
||||
bool isFlat(); // factor 4 ==> < 15°
|
||||
bool isFlat(); // factor 4 ==> < 15°
|
||||
|
||||
void setA(float a) { _a = abs(a); };
|
||||
void setB(float b) { _b = abs(b); };
|
||||
float getA() { return _a; };
|
||||
float getB() { return _b; };
|
||||
void setA(float a); // uses abs(a)
|
||||
void setB(float b); // uses abs(b)
|
||||
float getA();
|
||||
float getB();
|
||||
float getC();
|
||||
|
||||
float getLongRadius();
|
||||
float getShortRadius();
|
||||
|
||||
// experimental
|
||||
// returns the angle if the ellipse was the shadow of a circle.
|
||||
float angle();
|
||||
|
@ -15,7 +15,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/ellipse.git"
|
||||
},
|
||||
"version": "0.1.1",
|
||||
"version": "0.1.2",
|
||||
"license": "MIT",
|
||||
"frameworks": "*",
|
||||
"platforms": "*"
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=ellipse
|
||||
version=0.1.1
|
||||
version=0.1.2
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for ellipse class
|
||||
|
@ -29,6 +29,7 @@
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "ELLIPSE_LIB_VERSION: %s\n", (char*) ELLIPSE_LIB_VERSION);
|
||||
}
|
||||
|
||||
|
||||
@ -39,8 +40,6 @@ unittest_teardown()
|
||||
|
||||
unittest(test_constructor)
|
||||
{
|
||||
fprintf(stderr, "ELLIPSE_LIB_VERSION: %s\n", (char*) ELLIPSE_LIB_VERSION);
|
||||
|
||||
ellipse E(1.0, 1.0);
|
||||
fprintf(stderr, "%03.8f\n", E.getA());
|
||||
fprintf(stderr, "%03.8f\n", E.getB());
|
||||
|
Loading…
Reference in New Issue
Block a user