From 9ee8dde710d187e50a41b506dda24d49c10f3445 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 17 Sep 2002 04:00:09 +0000 Subject: [PATCH] Added Ramanujan's formula for an approximation of the circumference of an ellipse. I didn't end up using it in the ArcPath, but it will surely come in handy eventually. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@1690 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- src/java/com/threerings/media/util/MathUtil.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/java/com/threerings/media/util/MathUtil.java b/src/java/com/threerings/media/util/MathUtil.java index 0b2ce68a5..d63cc7e8f 100644 --- a/src/java/com/threerings/media/util/MathUtil.java +++ b/src/java/com/threerings/media/util/MathUtil.java @@ -1,5 +1,5 @@ // -// $Id: MathUtil.java,v 1.4 2002/05/17 21:13:03 mdb Exp $ +// $Id: MathUtil.java,v 1.5 2002/09/17 04:00:09 mdb Exp $ package com.threerings.media.util; @@ -45,4 +45,15 @@ public class MathUtil { return lineToString(p1.x, p1.y, p2.x, p2.y); } + + /** + * Returns the approximate circumference of the ellipse defined by the + * specified minor and major axes. The formula used (due to Ramanujan, + * via a paper of his entitled "Modular Equations and Approximations + * to Pi"), is Pi(3a + 3b - sqrt[(a+3b)(b+3a)]). + */ + public static double ellipseCircum (double a, double b) + { + return Math.PI * (3*a + 3*b - Math.sqrt((a + 3*b) * (b + 3*a))); + } }