0.1.4 ellipse

This commit is contained in:
Rob Tillaart 2024-05-10 13:54:39 +02:00
parent f08c33cf1a
commit 5670e6f1b8
11 changed files with 227 additions and 18 deletions

View File

@ -6,11 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
## [0.1.2] - 2023-10-25
## [0.1.4] - 2024-05-06
- add **float perimeter_Parker()**
- update **ellipse_performance.ino**
- add **ellipse_performance2.ino** (table form)
- update keywords.txt
- minor edits
## [0.1.3] - 2023-10-25
- update readme.md
- update keywords.txt
## [0.1.2] - 2022-11-02
- add changelog.md
- add rp2040 to build-CI

View File

@ -11,7 +11,7 @@
# ellipse
Arduino library with ellipse math
Arduino library with ellipse math.
## Description
@ -19,7 +19,8 @@ Arduino library with ellipse math
This experimental library provides basic ellipse math.
It was written to test different perimeter algorithms.
Trigger was a video of Dr. Matt Parker.
Trigger was a video of Dr. Matt Parker, with the title:
"Why is there no equation for the perimeter of an ellipse?"
https://www.youtube.com/watch?v=5nW3nJhBHL0
@ -48,9 +49,10 @@ Perimeter == circumference
- **float perimeter_ref()** slower but best known algorithm (Ramanujan 2)
- **float perimeter_Keppler()** good and fast algorithm for eccentricity between 1 and 2.
- **float perimeter_Ramanujan1()** good algorithm.
- **float perimeter_Parker()** Matt Parker's algorithm, better than Ramanujan, but not symmetric.
- **float perimeter_Ramanujan2()** slow but best known algorithm.
See performance example for differences in timing.
See performance example for differences in timing and accuracy.
#### Convenience functions

View File

@ -2,7 +2,7 @@
// FILE: ellipse.cpp
// AUTHOR: Rob Tillaart
// DATE: 2021-10-31
// VERSION: 0.1.3
// VERSION: 0.1.4
// PURPOSE: Arduino library for ellipse maths
// URL: https://github.com/RobTillaart/ellipse
// TRIGGER: https://www.youtube.com/watch?v=5nW3nJhBHL0
@ -38,7 +38,7 @@ float ellipse::perimeter_ref()
float ellipse::perimeter_Keppler()
{
// Keppler
float p = 2 * PI * (_a + _b) / 2; // very fast for a ~ b
float p = 2 * PI * (_a + _b) / 2; // very fast for a ~ b
return p;
}
@ -50,7 +50,19 @@ float ellipse::perimeter_Ramanujan1()
float a3 = 3 * _a;
float b3 = 3 * _b;
float p = PI * (a3 + b3 - sqrt( (a3 + _b)*(_a + b3)));
// one float operation less (~7% faster)
// one float operation less (~7% faster)
return p;
}
float ellipse::perimeter_Parker()
{
// Matthew Parker, better than Ramanujan 1 for e > ~2.4
// not symmetric. _a should be longest.
float a = (_a > _b) ? _a : _b;
float b = (_a > _b) ? _b : _a;
float t = sqrt(269 * a * a + 667 * a * b + 371 * b * b); // 269=prime 667=23*29 371=7*53
float p = PI * ((53.0/3.0) * a + (717.0/35.0) * b - t);
return p;
}

View File

@ -3,14 +3,14 @@
// FILE: ellipse.h
// AUTHOR: Rob Tillaart
// DATE: 2021-10-31
// VERSION: 0.1.3
// VERSION: 0.1.4
// PURPOSE: Arduino library for ellipse maths
// URL: https://github.com/RobTillaart/ellipse
#include "Arduino.h"
#define ELLIPSE_LIB_VERSION (F("0.1.3"))
#define ELLIPSE_LIB_VERSION (F("0.1.4"))
class ellipse
@ -23,6 +23,7 @@ public:
float perimeter_ref(); // pretty slow but very good over long range
float perimeter_Keppler();
float perimeter_Ramanujan1();
float perimeter_Parker();
float perimeter_Ramanujan2();
float eccentricity();

View File

@ -1,7 +1,7 @@
//
// FILE: ellipse_performance.ino
// AUTHOR: Rob Tillaart
// PURPOSE: demo
// PURPOSE: performance and accuracy test
// DATE: 2021-10-31
// URL: https://github.com/RobTillaart/ellipse
@ -26,6 +26,7 @@ void setup()
test_circumference();
test_perimeter_ref();
test_perimeter_keppler();
test_perimeter_parker();
test_eccentricity();
Serial.println("\nEllipse A=10, B=5");
@ -34,6 +35,7 @@ void setup()
test_circumference();
test_perimeter_ref();
test_perimeter_keppler();
test_perimeter_parker();
test_eccentricity();
Serial.println("\nEllipse A=10, B=1");
@ -42,11 +44,10 @@ void setup()
test_circumference();
test_perimeter_ref();
test_perimeter_keppler();
test_perimeter_parker();
test_eccentricity();
Serial.println("\nDone...");
}
@ -65,7 +66,7 @@ void test_circumference()
Serial.print("\tTIME: ");
Serial.print(stop - start);
Serial.print("\tCIRCUMFERENCE: ");
Serial.println(f);
Serial.println(f, 4);
delay(100);
}
@ -79,7 +80,7 @@ void test_perimeter_ref()
Serial.print("\tTIME: ");
Serial.print(stop - start);
Serial.print("\tCIRCUMFERENCE: ");
Serial.println(f);
Serial.println(f, 4);
delay(100);
}
@ -93,7 +94,21 @@ void test_perimeter_keppler()
Serial.print("\tTIME: ");
Serial.print(stop - start);
Serial.print("\tCIRCUMFERENCE: ");
Serial.println(f);
Serial.println(f, 4);
delay(100);
}
void test_perimeter_parker()
{
Serial.println(__FUNCTION__);
start = micros();
f = E.perimeter_Parker();
stop = micros();
Serial.print("\tTIME: ");
Serial.print(stop - start);
Serial.print("\tCIRCUMFERENCE: ");
Serial.println(f, 4);
delay(100);
}

View File

@ -0,0 +1,45 @@
Arduino UNO
IDE 1.18.19
ellipse_performance.ino
Ellipse A=10, B=10
test_circumference
TIME: 104 CIRCUMFERENCE: 62.8319
test_perimeter_ref
TIME: 120 CIRCUMFERENCE: 62.8319
test_perimeter_keppler
TIME: 36 CIRCUMFERENCE: 62.8319
test_perimeter_parker
TIME: 160 CIRCUMFERENCE: 62.8296
test_eccentricity
TIME: 8 ECCENTRICITY: 0.00
Ellipse A=10, B=5
test_circumference
TIME: 104 CIRCUMFERENCE: 48.4421
test_perimeter_ref
TIME: 188 CIRCUMFERENCE: 48.4422
test_perimeter_keppler
TIME: 32 CIRCUMFERENCE: 47.1239
test_perimeter_parker
TIME: 160 CIRCUMFERENCE: 48.4411
test_eccentricity
TIME: 104 ECCENTRICITY: 0.87
Ellipse A=10, B=1
test_circumference
TIME: 108 CIRCUMFERENCE: 40.6055
test_perimeter_ref
TIME: 188 CIRCUMFERENCE: 40.6393
test_perimeter_keppler
TIME: 36 CIRCUMFERENCE: 34.5575
test_perimeter_parker
TIME: 164 CIRCUMFERENCE: 40.5942
test_eccentricity
TIME: 108 ECCENTRICITY: 0.99
Done...
Done...

View File

@ -0,0 +1,95 @@
//
// FILE: ellipse_performance.ino
// AUTHOR: Rob Tillaart
// PURPOSE: performance and accuracy test
// DATE: 2021-10-31
// URL: https://github.com/RobTillaart/ellipse
#include "ellipse.h"
ellipse E(1, 1);
uint32_t start, stop;
volatile float f;
void setup()
{
Serial.begin(115200);
Serial.println(__FILE__);
Serial.println();
Serial.println(" A B t ECC t circum t Ramanu t Keppler t Parker");
Serial.println("================================================================================");
float A = 10;
float B = 10;
while (B > 0)
{
E.setA(A);
E.setB(B);
Serial.print(A);
Serial.print(", ");
Serial.print(B);
Serial.print(", ");
delay(100);
start = micros();
f = E.eccentricity();
stop = micros();
Serial.print(stop - start);
Serial.print(", ");
Serial.print(f, 4);
Serial.print(", ");
delay(100);
start = micros();
f = E.circumference();
stop = micros();
Serial.print(stop - start);
Serial.print(", ");
Serial.print(f, 4);
Serial.print(", ");
delay(100);
start = micros();
f = E.perimeter_ref();
stop = micros();
Serial.print(stop - start);
Serial.print(", ");
Serial.print(f, 4);
Serial.print(", ");
delay(100);
start = micros();
f = E.perimeter_Keppler();
stop = micros();
Serial.print(stop - start);
Serial.print(", ");
Serial.print(f, 4);
Serial.print(", ");
delay(100);
start = micros();
f = E.perimeter_Parker();
stop = micros();
Serial.print(stop - start);
Serial.print(", ");
Serial.print(f, 4);
delay(100);
Serial.println();
B = B - 0.5;
}
Serial.println("\nDone...");
}
void loop()
{
}
// -- END OF FILE --

View File

@ -0,0 +1,31 @@
Arduino UNO
IDE 1.18.19
ellipse_performance2.ino (slightly edited)
A B t ECC t circum t Ramanu t Keppler t Parker
================================================================================
10.00, 10.00, 8, 0.0000, 96, 62.8319, 104, 62.8319, 28, 62.8319, 148, 62.8296
10.00, 9.50, 100, 0.3122, 104, 61.2711, 180, 61.2711, 28, 61.2611, 148, 61.2704
10.00, 9.00, 96, 0.4359, 100, 59.7316, 172, 59.7316, 28, 59.6903, 156, 59.7319
10.00, 8.50, 100, 0.5268, 96, 58.2150, 172, 58.2150, 28, 58.1195, 148, 58.2157
10.00, 8.00, 100, 0.6000, 100, 56.7233, 176, 56.7233, 28, 56.5487, 148, 56.7241
10.00, 7.50, 100, 0.6614, 104, 55.2587, 180, 55.2587, 32, 54.9779, 148, 55.2594
10.00, 7.00, 92, 0.7141, 100, 53.8237, 176, 53.8237, 28, 53.4071, 148, 53.8238
10.00, 6.50, 104, 0.7599, 96, 52.4210, 180, 52.4210, 28, 51.8363, 144, 52.4207
10.00, 6.00, 92, 0.8000, 100, 51.0540, 176, 51.0540, 32, 50.2655, 148, 51.0532
10.00, 5.50, 96, 0.8352, 100, 49.7262, 172, 49.7263, 28, 48.6947, 148, 49.7252
10.00, 5.00, 96, 0.8660, 100, 48.4421, 176, 48.4422, 24, 47.1239, 148, 48.4411
10.00, 4.50, 96, 0.8930, 100, 47.2066, 180, 47.2069, 24, 45.5531, 152, 47.2060
10.00, 4.00, 96, 0.9165, 100, 46.0256, 172, 46.0262, 24, 43.9823, 148, 46.0258
10.00, 3.50, 100, 0.9367, 96, 44.9062, 176, 44.9074, 28, 42.4115, 140, 44.9077
10.00, 3.00, 96, 0.9539, 104, 43.8567, 172, 43.8591, 28, 40.8407, 144, 43.8595
10.00, 2.50, 100, 0.9682, 100, 42.8875, 176, 42.8921, 28, 39.2699, 152, 42.8912
10.00, 2.00, 104, 0.9798, 100, 42.0112, 176, 42.0201, 28, 37.6991, 148, 42.0142
10.00, 1.50, 96, 0.9887, 96, 41.2437, 172, 41.2609, 28, 36.1283, 148, 41.2429
10.00, 1.00, 100, 0.9950, 100, 40.6055, 176, 40.6393, 28, 34.5575, 152, 40.5942
10.00, 0.50, 96, 0.9987, 96, 40.1234, 176, 40.1922, 28, 32.9867, 148, 40.0895
Done...

View File

@ -10,6 +10,7 @@ circumference KEYWORD2
perimeter_ref KEYWORD2
perimeter_Keppler KEYWORD2
perimeter_Parker KEYWORD2
perimeter_Ramanujan1 KEYWORD2
perimeter_Ramanujan2 KEYWORD2

View File

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

View File

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