summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-05-28 23:55:07 -0700
committerFuwn <[email protected]>2022-05-28 23:55:07 -0700
commit460b0885d4eb0bcce4a4454945ff978e1f3ae4a4 (patch)
tree46b8170b8494f3452e80cc844fcb90995bf6f467
parentfeat(test.cc): debug precision (diff)
downloadellipse-460b0885d4eb0bcce4a4454945ff978e1f3ae4a4.tar.xz
ellipse-460b0885d4eb0bcce4a4454945ff978e1f3ae4a4.zip
feat(ellipse.cc): finish infinute sum approxs
-rw-r--r--ellipse/ellipse.cc97
1 files changed, 66 insertions, 31 deletions
diff --git a/ellipse/ellipse.cc b/ellipse/ellipse.cc
index eb13b69..fd4c34c 100644
--- a/ellipse/ellipse.cc
+++ b/ellipse/ellipse.cc
@@ -42,47 +42,82 @@ void ellipse::calculate() {
// 2 * pi *
// std::sqrt((std::pow(this->major, 2) + std::pow(this->minor, 2)) / 2);
- // A closer approximation, but still not 100% accurate for insanely large
- // axis.
- this->circumference =
- pi * std::abs((3 * (this->major + this->minor)) -
- std::sqrt(((3 * this->major) + this->minor) *
- (this->major + (3 * this->minor))));
-
- // Similar to the previous approximation, but more complicated and yields
- // negligible fruits relative to its cognitive complexity.
- // {
- // double h = std::pow(this->major - this->minor, 2) /
- // std::pow(this->major + this->minor, 2);
+ // A *mathematically* very close approximation.
+ // this->circumference =
+ // pi * std::abs((3 * (this->major + this->minor)) -
+ // std::sqrt(((3 * this->major) + this->minor) *
+ // (this->major + (3 * this->minor))));
+
+ // Similar to the previous approximation, but yields
+ // negligible fruits relative to its cognitive complexity. However, it is
+ // slightly more accurate for wildly large numbers, so I'll keep it.
+ {
+ double h = std::pow(this->major - this->minor, 2) /
+ std::pow(this->major + this->minor, 2);
+
+ this->circumference = pi * (this->major + this->minor) *
+ ((1 + ((3 * h)) / (10 + std::sqrt(4 - (3 * h)))));
+ }
+
+ // This belongs to the two calculates below.
+ // std::function<double(double)> factorial;
//
- // this->circumference = pi * (this->major + this->minor) *
- // ((1 + ((3 * h)) / (10 + std::sqrt(4 - (3 * h)))));
- // }
+ // factorial = [&factorial](double n) -> double {
+ // if (n > 1) {
+ // return n * factorial(n - 1);
+ // } else {
+ // return 1;
+ // }
+ // };
// I was going to attempt to get some kind of infinite series calculations
// involved, but it was just too boring... and probably out of the scope of
// this project anyway.
- // std::function<double(double)> factorial;
+
+ // You probably shouldn't try this on an ill-equipped computer...
+ // {
+ // double limit = std::numeric_limits<double>::infinity();
+ // double h = 0;
+ //
+ // for (int i = 1; i <= limit; ++i) {
+ // h += ((std::pow(factorial(2 * i), 2) /
+ // std::pow(std::pow(2, i) * factorial(i), 4)) *
+ // (std::pow(this->eccentricity, 2 * i) / ((2 * i) - 1)));
+ // }
+ //
+ // this->circumference = 2 * this->major * pi * (1 - h);
+ // }
+
+ // Or this either... however, it is not complete enough to guarantee 100%
+ // accurate results.
+ // {
+ // double limit = std::numeric_limits<double>::infinity();
+ // double infinite_sum = 0;
+ // double h = std::pow(this->major - this->minor, 2) /
+ // std::pow(this->major + this->minor, 2);
+ // std::function<double(double, double)> binomial_coefficient =
+ // [](double n, double k) -> double {
+ // double r = 1;
//
- // factorial = [&factorial](double n) -> double {
- // if (n > 1) {
- // return n * factorial(n - 1);
- // } else {
- // return 1;
+ // if (k > n - k) {
+ // k = n - k;
// }
- // };
//
- // {
- // double i = std::numeric_limits<double>::infinity();
+ // for (int i = 0; i < k; ++i) {
+ // r *= (n - i);
+ // r /= (i + 1);
+ // }
+ //
+ // return r;
+ // };
//
- // this->circumference = 2 * this->major * pi *
- // (1 - (std::pow(factorial(2 * i), 2) /
- // std::pow(std::pow(2, i) * factorial(i),
- // 4))
- // *
- // ((std::pow(this->eccentricity, 2 * i) /
- // ((2 * i) - 1))));
+ // for (int n = 0; n <= limit; ++n) {
+ // infinite_sum +=
+ // (std::pow(binomial_coefficient(n, 0.5), 2) * std::pow(h, n));
// }
+ //
+ // this->circumference = pi * (this->major + this->minor) * infinite_sum;
+ // }
}
// double ellipse::get_major() { return this->major; }