0.1.1 ellipse

This commit is contained in:
rob tillaart 2022-07-25 09:40:13 +02:00
parent 7f65d0c013
commit 76c77a286d
7 changed files with 99 additions and 10 deletions

View File

@ -44,6 +44,18 @@ This is an indication of flatness of the ellipse. 0 is a circle 1 is flat line.
See performance example for differences in timing.
#### Misc
- **bool isCircle(float epsilon = 0.0)** | a - b | < eps.
- **bool isFlat()** true if a > 4b, where a = longest radius.
#### Experimental
- **float angle()** returns the angle if the ellipse was the
shadow of a circle, Returns 0..90°, 0° == circle, 90° == line.
## Operation
See examples.
@ -54,10 +66,10 @@ See examples.
- make constructor symmetric (a < b or a > b ==> all possible.
- make other code symmetric.
- additional functions
- **bool isCircle()** a == b
- **bool isFlat()** a > 4 \* b ?
- bresenham to draw ellipse?
- Bresenham to draw ellipse?
- **float getLongRadius()**
- **float getShortRadius()**
- move all code to .cpp
- documentation
- refer wikipedia.
- refer Wikipedia.

View File

@ -2,13 +2,16 @@
// FILE: ellipse.cpp
// AUTHOR: Rob Tillaart
// DATE: 2021-10-31
// VERSION: 0.1.0
// VERSION: 0.1.1
// 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
#include "ellipse.h"
@ -79,12 +82,28 @@ float ellipse::area()
float ellipse::eccentricity()
{
if (_a == _b) return 0; // quick circle check.
float x = _a * _a - _b * _b;
if (x < 0) x = -1 * x;
return sqrt(x)/ _a;
}
bool ellipse::isCircle(float epsilon)
{
if (epsilon == 0) return (_a == _b);
float delta = abs(_a - _b);
return (delta < epsilon);
}
bool ellipse::isFlat()
{
if (_a > _b) return (_a > (4 * _b));
return (_b > (4 * _a));
}
float ellipse::getC()
{
float e = eccentricity();
@ -93,5 +112,11 @@ float ellipse::getC()
}
float ellipse::angle()
{
float c = (_b < _a) ? _b/_a : _a/_b;
return acos(c) * (180 / PI);
}
// -- END OF FILE --

View File

@ -3,7 +3,7 @@
// FILE: ellipse.h
// AUTHOR: Rob Tillaart
// DATE: 2021-10-31
// VERSION: 0.1.0
// VERSION: 0.1.1
// PURPOSE: Arduino library for ellipse maths
// URL: https://github.com/RobTillaart/ellipse
//
@ -11,7 +11,7 @@
#include "Arduino.h"
#define ELLIPSE_LIB_VERSION (F("0.1.0"))
#define ELLIPSE_LIB_VERSION (F("0.1.1"))
class ellipse
@ -24,7 +24,11 @@ public:
float perimeter_Keppler();
float perimeter_Ramanujan1();
float perimeter_Ramanujan2();
float eccentricity();
// convenience functions.
bool isCircle(float epsilon = 0.0);
bool isFlat(); // factor 4 ==> < 15°
void setA(float a) { _a = abs(a); };
void setB(float b) { _b = abs(b); };
@ -32,6 +36,10 @@ public:
float getB() { return _b; };
float getC();
// experimental
// returns the angle if the ellipse was the shadow of a circle.
float angle();
private:
float _a;
float _b;

View File

@ -0,0 +1,42 @@
//
// FILE: ellipse_angle.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// URL: https://github.com/RobTillaart/ellipse
//
// use the plotter tool to see the angle() curve.
//
#include "ellipse.h"
ellipse el(1, 1);
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.println();
for (int a = 1; a <= 500; a++)
{
el.setA(1 + a * 0.002);
Serial.print(el.getB(), 2);
Serial.print('\t');
Serial.print(el.getA(), 4);
Serial.print('\t');
Serial.print(el.angle(), 4);
Serial.print('\n');
}
Serial.println("\nDone...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -21,6 +21,8 @@ getA KEYWORD2
getB KEYWORD2
getC KEYWORD2
angle KEYWORD2
# Constants (LITERAL1)
FLE_LIB_VERSION LITERAL1

View File

@ -15,7 +15,7 @@
"type": "git",
"url": "https://github.com/RobTillaart/ellipse.git"
},
"version": "0.1.0",
"version": "0.1.1",
"license": "MIT",
"frameworks": "*",
"platforms": "*"

View File

@ -1,5 +1,5 @@
name=ellipse
version=0.1.0
version=0.1.1
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for ellipse class