HP Forums
(12C Platinum) Length of An Ellipse - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (12C Platinum) Length of An Ellipse (/thread-13242.html)



(12C Platinum) Length of An Ellipse - Gamo - 07-07-2019 05:44 AM

Calculate the Length of an ellipse according to this series formula:

[attachment=7449]

[attachment=7450]

-------------------------
Example: FIX 5
a = 50
b = 10

50 [ENTER] 10 [R/S] display 210.08595

------------------------
Program: RPN mode: "Program run this formula in three terms"
Code:
 
001 STO 2
002 R↓
003 STO 1
004 RCL 2
005  -
006 RCL 1
007 RCL 2
008  +
009 STO 3
010  ÷
------------
011 STO 0
012 X^2
013  4
014  ÷
015  1
016  +
017 RCL 0
018  4
019 Y^X
020  6
----------
021  4
022  ÷
023  +
024 RCL 0
025  6
026 Y^X
027  2
028  5
029  6
030  ÷
---------
031  +
032  3
033  5
034  5
035 ENTER
036  1
037  1
038  3
039  ÷
040 RCL 3
041  x
042  x

Gamo


RE: (12C Platinum) Length of An Ellipse - Leviset - 07-07-2019 10:35 AM

Attached a number of approximations & infinite series to calculate the perimeter of an Ellipse.


RE: (12C Platinum) Length of An Ellipse - Albert Chan - 07-07-2019 04:06 PM

(07-07-2019 05:44 AM)Gamo Wrote:  Program: RPN mode: "Program run this formula in three terms" ...

You might consider Ramanujan's approximation, less code and almost 2 extra terms!

Replace steps 011-031 with this:
Quote:011 Enter
012 x ; h = ((a-b)/(a+b))^2
013 3
014 x
015 Enter
016 Enter
017 4
018 -
019 CHS
020 SQRT
021 1
022 0
023 +
024 /
025 1
026 + ; correction = 1 + 3h / (10 + sqrt(4-3h))

Using your example, a=50, b=10, FIX 5, we get ellipse perimeter = 210.10028, absolute error = -0.00017


RE: (12C Platinum) Length of An Ellipse - Gamo - 07-08-2019 04:51 AM

Thanks Albert Chan

That formula is much simple as stated in the link

"The simplest formula possible for the circumference of a general ellipse"

Gamo


RE: (12C Platinum) Length of An Ellipse - Albert Chan - 07-08-2019 02:53 PM

(07-07-2019 04:06 PM)Albert Chan Wrote:  a=50, b=10, FIX 5, we get ellipse perimeter = 210.10028, absolute error = -0.00017

FYI, absolute error based on ellipse perimeter AGM2 method:

(50, 10) repeated AGM:
→ (30 , √(500) ≅ 22.36067977), gap = 7.63932023
→ (26.18033989, 25.90020064), gap = 0.28013825
→ (26.04027027, 26.03989355), gap = 0.00037672
→ (26.04008191, 26.04008191)

effective radius = (30² - (0.5)(7.63932023²) - (1)(0.28013825²) - (2)(0.00037672²)) / 26.04008191 = 33.43852445

ellipse perimeter = 2 * pi * 33.43852445 = 210.1004455 ≅ 210.10045


RE: (12C Platinum) Length of An Ellipse - John Keith - 07-23-2019 05:06 PM

I have tried several of these methods and I believe that Ramanujan's approximation is the clear winner. It gives 6 - 9 digits of accuracy for reasonable ellipses and is small and fast. For exact solutions, Albert's AGM2 program is fastest by far, almost 200* as fast as numerical integration on the HP 50! The Gauss-Kummer infinite series (series 2 from the PDF in post #2) looks good but the terms are very slow to compute and the program is large and complicated.

At the risk of trolling this thread I am posting HP-48 versions of the programs for those who may be interested.

Ramanujan:

Code:

\<< DUP2 - ROT ROT + DUP \pi \->NUM * ROT ROT / SQ 3. * 4. OVER - \v/ 10. + / 1. + *
\>>

For the HP 50, ROT ROT can be replaced by UNROT.

AGM2:

Code:

\<< DUP2 SQ SWAP SQ + .5 * .25 0. 0. \-> a b s t k s1
  \<<
    WHILE b a - 'k' STO s t k SQ * - 's1' STO s s1 \=/
    REPEAT a b * \v/ 'b' STO 'a' k .5 * STO+ s1 's' STO t 't' STO+
    END \pi \->NUM 2. * s * k .5 * a + /
  \>>
\>>

This is just a straightforward translation of Albert's Lua code which could be made smaller and faster by moving local variables to the stack at the cost of readability (and effort!).


RE: (12C Platinum) Length of An Ellipse - Albert Chan - 01-16-2020 10:18 PM

For ellipse perimeter using integrals, we can use Weierstrass Substitution.

\(t = \tan(x/2)\quad\quad\quad → dt = sec^2(x/2)/2\;dx\quad\quad\quad\quad\quad\quad
\; → dx = \left({2\over 1+t^2}\right)\;dt \)

Ellipse perimeter = \(4a \int _0 ^{\pi \over 2} \sqrt{1 - e^2\sin^2 x}\;dx
= 4a \int _0 ^1 \sqrt{1 - e^2\left({2t \over 1+t^2}\right)^2}
\left({2\over 1+t^2}\right)\;dt \)

Example, Casio FX-115ES Plus, a=50, b=10 → e² = 1-(b/a)² = 24/25

Perimeter   = 210.100445396890       // 4*50*EllipticE(24/25)
dx integral = 210.100445053320       // time = 4.0 sec
dt integral = 210.100445398816       // time = 2.8 sec

Turns out dx integral work better with simple Trapezoidal rule !

John D Cook's blog: Three surprises with the trapezoid rule
Quote:2. Although the trapezoid rule is inefficient in general, it can be shockingly efficient for periodic functions.

Redo above example for ellipse perimeter. (n = number of trapezoids)
Code:
n   dx trapezoid    dx simpson      dx romberg
2   207.519513599   213.860831727
4   209.945722803   210.754459204   210.547367702
8   210.098446673   210.149354630   210.102056335
16  210.100444351   210.101110244   210.097700423
32  210.100445397   210.100445745   210.100454618
64                  210.100445397   210.100446082
128                                 210.100445394
256                                 210.100445397