Skip to content

Commit 76c77a2

Browse files
committed
0.1.1 ellipse
1 parent 7f65d0c commit 76c77a2

File tree

7 files changed

+99
-10
lines changed

7 files changed

+99
-10
lines changed

libraries/ellipse/README.md

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@ This is an indication of flatness of the ellipse. 0 is a circle 1 is flat line.
4444
See performance example for differences in timing.
4545

4646

47+
#### Misc
48+
49+
- **bool isCircle(float epsilon = 0.0)** | a - b | < eps.
50+
- **bool isFlat()** true if a > 4b, where a = longest radius.
51+
52+
53+
#### Experimental
54+
55+
- **float angle()** returns the angle if the ellipse was the
56+
shadow of a circle, Returns 0..90°, 0° == circle, 90° == line.
57+
58+
4759
## Operation
4860

4961
See examples.
@@ -54,10 +66,10 @@ See examples.
5466
- make constructor symmetric (a < b or a > b ==> all possible.
5567
- make other code symmetric.
5668
- additional functions
57-
- **bool isCircle()** a == b
58-
- **bool isFlat()** a > 4 \* b ?
59-
- bresenham to draw ellipse?
69+
- Bresenham to draw ellipse?
70+
- **float getLongRadius()**
71+
- **float getShortRadius()**
72+
- move all code to .cpp
6073
- documentation
61-
- refer wikipedia.
62-
74+
- refer Wikipedia.
6375

libraries/ellipse/ellipse.cpp

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
// FILE: ellipse.cpp
33
// AUTHOR: Rob Tillaart
44
// DATE: 2021-10-31
5-
// VERSION: 0.1.0
5+
// VERSION: 0.1.1
66
// PURPOSE: Arduino library for ellipse maths
77
// URL: https://github.com/RobTillaart/ellipse
88
// TRIGGER: https://www.youtube.com/watch?v=5nW3nJhBHL0
99
//
1010
// HISTORY:
1111
// 0.1.0 2021-10-31 initial version
12+
// 0.1.1 2022-07- add angle() + example
13+
// add isCircle(), isFlat()
14+
// update readme.md
1215

1316

1417
#include "ellipse.h"
@@ -79,12 +82,28 @@ float ellipse::area()
7982

8083
float ellipse::eccentricity()
8184
{
85+
if (_a == _b) return 0; // quick circle check.
8286
float x = _a * _a - _b * _b;
8387
if (x < 0) x = -1 * x;
8488
return sqrt(x)/ _a;
8589
}
8690

8791

92+
bool ellipse::isCircle(float epsilon)
93+
{
94+
if (epsilon == 0) return (_a == _b);
95+
float delta = abs(_a - _b);
96+
return (delta < epsilon);
97+
}
98+
99+
100+
bool ellipse::isFlat()
101+
{
102+
if (_a > _b) return (_a > (4 * _b));
103+
return (_b > (4 * _a));
104+
}
105+
106+
88107
float ellipse::getC()
89108
{
90109
float e = eccentricity();
@@ -93,5 +112,11 @@ float ellipse::getC()
93112
}
94113

95114

115+
float ellipse::angle()
116+
{
117+
float c = (_b < _a) ? _b/_a : _a/_b;
118+
return acos(c) * (180 / PI);
119+
}
120+
96121
// -- END OF FILE --
97122

libraries/ellipse/ellipse.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
// FILE: ellipse.h
44
// AUTHOR: Rob Tillaart
55
// DATE: 2021-10-31
6-
// VERSION: 0.1.0
6+
// VERSION: 0.1.1
77
// PURPOSE: Arduino library for ellipse maths
88
// URL: https://github.com/RobTillaart/ellipse
99
//
1010

1111

1212
#include "Arduino.h"
1313

14-
#define ELLIPSE_LIB_VERSION (F("0.1.0"))
14+
#define ELLIPSE_LIB_VERSION (F("0.1.1"))
1515

1616

1717
class ellipse
@@ -24,14 +24,22 @@ class ellipse
2424
float perimeter_Keppler();
2525
float perimeter_Ramanujan1();
2626
float perimeter_Ramanujan2();
27+
2728
float eccentricity();
29+
// convenience functions.
30+
bool isCircle(float epsilon = 0.0);
31+
bool isFlat(); // factor 4 ==> < 15°
2832

2933
void setA(float a) { _a = abs(a); };
3034
void setB(float b) { _b = abs(b); };
3135
float getA() { return _a; };
3236
float getB() { return _b; };
3337
float getC();
3438

39+
// experimental
40+
// returns the angle if the ellipse was the shadow of a circle.
41+
float angle();
42+
3543
private:
3644
float _a;
3745
float _b;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
//
2+
// FILE: ellipse_angle.ino
3+
// AUTHOR: Rob Tillaart
4+
// PURPOSE: demo
5+
// URL: https://github.com/RobTillaart/ellipse
6+
//
7+
// use the plotter tool to see the angle() curve.
8+
//
9+
10+
#include "ellipse.h"
11+
12+
13+
ellipse el(1, 1);
14+
15+
16+
void setup()
17+
{
18+
Serial.begin(115200);
19+
Serial.println(__FILE__);
20+
Serial.println();
21+
22+
for (int a = 1; a <= 500; a++)
23+
{
24+
el.setA(1 + a * 0.002);
25+
Serial.print(el.getB(), 2);
26+
Serial.print('\t');
27+
Serial.print(el.getA(), 4);
28+
Serial.print('\t');
29+
Serial.print(el.angle(), 4);
30+
Serial.print('\n');
31+
}
32+
33+
Serial.println("\nDone...");
34+
}
35+
36+
37+
void loop()
38+
{
39+
}
40+
41+
42+
// -- END OF FILE --

libraries/ellipse/keywords.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ getA KEYWORD2
2121
getB KEYWORD2
2222
getC KEYWORD2
2323

24+
angle KEYWORD2
25+
2426

2527
# Constants (LITERAL1)
2628
FLE_LIB_VERSION LITERAL1

libraries/ellipse/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/ellipse.git"
1717
},
18-
"version": "0.1.0",
18+
"version": "0.1.1",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*"

libraries/ellipse/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ellipse
2-
version=0.1.0
2+
version=0.1.1
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino library for ellipse class

0 commit comments

Comments
 (0)