Post Reply 
Perimeter of Ellipse
03-05-2016, 04:19 PM
Post: #1
Perimeter of Ellipse
Although simple formulae for the perimeter of an ellipse exist, they are only approximations. Exact formulae are complicated. The following program uses a converging iteration technique instead. Ported from a QBASIC program by Gérard P. Michon.

Syntax: EllipsePerimeter(a,b), where a & b are the lengths of the axes (order doesn't matter)
Output: perimeter of ellipse

Examples:
EllipsePerimeter(0.5, 0.5) --> 3.14159265359
EllipsePerimeter(3, 4) --> 22.1034921607

Code:
gk(h);
cayley(x);

EXPORT EllipsePerimeter(a,b)
BEGIN
LOCAL x,h,P;
a:=ABS(a);
b:=ABS(b);
IF a < b THEN x:=a; a:=b; b:=x; END;
IF b < 0.28*a THEN
 P := 4*a*cayley((b/a)^2);
ELSE
 h := ((a-b)/(a+b))^2;
 P := pI*(a+b)*gk(h);
END;
RETURN P;
END
;

gk(h)
BEGIN
LOCAL z,x,n;
z := 0; x := 1; n := 0;
WHILE z + x <> z
 DO
 n := n + 1;
 x := h * x * ((n-1.5)/n)^2;
 z := z + x;
END;
RETURN 1 + z;
END;

cayley(x)
BEGIN
LOCAL y,t,n,z,u,v,w;
y := LOG(16 / x) - 1;
t := x / 4;
n := 1;
z := 0;
u := t * y;
v := (n - .5) / n;
w := .5 / ((n - .5) * n);
WHILE z <> z + u
 DO
 z := z + u;
 n := n + 1;
 t := x * t * v;
 v := (n - .5) / n;
 t := t * v;
 y := y - w;
 w := .5 / ((n - .5) * n);
 y := y - w;
 u := t * y;
END;
RETURN 1 + z;
END;

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Perimeter of Ellipse - Joe Horn - 03-05-2016 04:19 PM
RE: Perimeter of Ellipse - Wes Loewer - 03-06-2016, 11:55 AM
RE: Perimeter of Ellipse - Wes Loewer - 03-06-2016, 02:16 PM
RE: Perimeter of Ellipse - Joe Horn - 03-07-2016, 03:34 PM
RE: Perimeter of Ellipse - ggauny@live.fr - 07-11-2019, 05:02 PM
RE: Perimeter of Ellipse - TASP - 03-06-2016, 02:40 PM
RE: Perimeter of Ellipse - parisse - 03-06-2016, 06:42 PM
RE: Perimeter of Ellipse - SlideRule - 03-07-2016, 01:16 PM
RE: Perimeter of Ellipse - parisse - 03-09-2016, 08:39 AM
RE: Perimeter of Ellipse - Albert Chan - 03-24-2019, 12:42 PM
RE: Perimeter of Ellipse - Albert Chan - 01-19-2020, 03:56 AM
RE: Perimeter of Ellipse - Albert Chan - 01-19-2020, 11:00 PM
RE: Perimeter of Ellipse - Albert Chan - 01-21-2020, 05:16 PM
RE: Perimeter of Ellipse - Albert Chan - 01-23-2020, 01:40 PM
RE: Perimeter of Ellipse - Albert Chan - 06-05-2020, 03:28 AM
RE: Perimeter of Ellipse - Albert Chan - 08-01-2020, 12:31 PM
RE: Perimeter of Ellipse - Albert Chan - 06-06-2020, 05:12 PM
RE: Perimeter of Ellipse - hazem - 04-11-2023, 09:43 PM
RE: Perimeter of Ellipse - rprosperi - 04-12-2023, 01:53 AM
RE: Perimeter of Ellipse - hazem - 04-13-2023, 02:06 PM
RE: Perimeter of Ellipse - floppy - 04-13-2023, 02:20 PM
RE: Perimeter of Ellipse - Werner - 04-12-2023, 05:43 AM
RE: Perimeter of Ellipse - rprosperi - 04-12-2023, 12:44 PM
RE: Perimeter of Ellipse - floppy - 04-12-2023, 07:22 PM
RE: Perimeter of Ellipse - Albert Chan - 04-13-2023, 05:23 PM
RE: Perimeter of Ellipse - floppy - 04-15-2023, 06:21 PM



User(s) browsing this thread: 1 Guest(s)