View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.misc
David Biddulph[_2_] David Biddulph[_2_] is offline
external usenet poster
 
Posts: 8,651
Default Calculate the Circumference of an ellipse

You may need to read the Wikipedia piece again to resolve your confusion.
The table shows Pr, the perimetric radius. The circumference is 2*PI()*Pr.
--
David Biddulph

"JLatham" wrote in message
...
I won't say how confused I am at this point; as it seems amazing to me that
a
circle with a radius of 10000 has a perimeter of 62753+, while an ellipse
with major semi-axis of 10000 and minor semi-axis of 9975 has a perimeter
of
'only' 9987.5. But I'm just going by the table provided on the Wikipedia
page....

Nevertheless, here are two functions that are based on the same thing that
the worksheet formula was, and that give the same results. The only
difference in the two is that in one, I broke out some of the mid-formula
calculations and do it all in 4 lines of code, while in the 2nd one, it's
all
done in 1 calculation.

Function Ram2Perimeter(majorAxis As Double, minorAxis As Double) As Double
'uses Ramanujan's second formula to approximate the
'perimeter of an ellipse
'INPUTS: majorAxis = the major semi-axis value
' minorAxis = the minor semi-axis value
'OUTPUTS: estimated circumference, or
' if major semi-axis is = minor semi-axis,
' returns circumference of circle of 2*semi-axis diameter
' -1 if error encountered
'
'Reference: http://en.wikipedia.org/wiki/Circumference
'
'worksheet equivalent formula where
' B1 holds the majorAxis value and
' B2 holds the minorAxis value
'note that this does not account for circles
' combine these into one long formula for a worksheet:
'=(0.5*($B$1+A5))*(1+((3*(($B$1-A5)/($B$1+A5))^2)/
'(10+SQRT((4-(3*(($B$1-A5)/($B$1+A5))^2))))))
'
Dim swapValue As Double
Dim majorPlusMinor As Double
Dim majorMinusMinor As Double
Dim quotentSquared As Double
On Error GoTo RamanujanCirErr
'no such thing as negative numbers here!
majorAxis = Abs(majorAxis)
minorAxis = Abs(minorAxis)
'just to be technical, if minor axis major axis, swap
If minorAxis majorAxis Then
swapValue = majorAxis
majorAxis = minorAxis
minorAxis = swapValue
End If
'special case: if majorAxis=minorAxis, then it's a circle
If majorAxis = minorAxis Then
Ram2Perimeter = (4 * Atn(1)) * (2 * majorAxis) ' = pi*D
Exit Function
End If
majorPlusMinor = majorAxis + minorAxis
majorMinusMinor = majorAxis - minorAxis
quotentSquared = (majorMinusMinor / majorPlusMinor) ^ 2
Ram2Perimeter = (0.5 * majorPlusMinor) * _
(1 + ((3 * quotentSquared / _
(10 + Sqr((4 - 3 * quotentSquared))))))
On Error GoTo 0
Exit Function
RamanujanCirErr:
Err.Clear
Ram2Perimeter = -1
End Function

Function Ram2Perimeter2(majorAxis As Double, minorAxis As Double) As
Double
'uses Ramanujan's second formula to approximate the
'perimeter of an ellipse
'INPUTS: majorAxis = the major semi-axis value
' minorAxis = the minor semi-axis value
'OUTPUTS: estimated circumference, or
' if major semi-axis is = minor semi-axis,
' returns circumference of circle of 2*semi-axis diameter
' -1 if error encountered
'
'Reference: http://en.wikipedia.org/wiki/Circumference
'
'worksheet equivalent formula where
' B1 holds the majorAxis value and
' B2 holds the minorAxis value
'note that this does not account for circles
' combine these into one long formula for a worksheet:
'=(0.5*($B$1+A5))*(1+((3*(($B$1-A5)/($B$1+A5))^2)/
'(10+SQRT((4-(3*(($B$1-A5)/($B$1+A5))^2))))))
'
Dim swapValue As Double
On Error GoTo RamanujanCir2Err
'no such thing as negative numbers here!
majorAxis = Abs(majorAxis)
minorAxis = Abs(minorAxis)
'just to be technical, if minor axis major axis, swap
If minorAxis majorAxis Then
swapValue = majorAxis
majorAxis = minorAxis
minorAxis = swapValue
End If
'special case: if majorAxis=minorAxis, then it's a circle
If majorAxis = minorAxis Then
Ram2Perimeter2 = (4 * Atn(1)) * (2 * majorAxis) ' = pi*D
Exit Function
End If
Ram2Perimeter2 = (0.5 * (majorAxis + minorAxis)) * _
(1 + ((3 * (((majorAxis - minorAxis) / (majorAxis + minorAxis)) ^ 2) / _
(10 + Sqr((4 - 3 * (((majorAxis - minorAxis) / (majorAxis + minorAxis))
^
2)))))))
On Error GoTo 0
Exit Function
RamanujanCir2Err:
Err.Clear
Ram2Perimeter2 = -1
End Function



"Dana DeLouis" wrote:

Hi J. Maybe we can expand your excellent reference to a Custom
function. Here, we factor out a common expression, and add in the 2 Pi
to get the Perimeter. This uses the first example from your reference:

Sub TestIt()
'// Ellipse Perimeter
Debug.Print Perimeter(10000, 9975)
End Sub

Function Perimeter(a, b)
Dim k As Double

k = 3 * ((a - b) / (a + b)) ^ 2
Perimeter = (a + b) * (1 + k / (10 + Sqr(4 - k))) * [Pi()]
End Function

Returns:
62753.3378298691

I get the same result using a math program...
a = 10000;
b = 9975.;
4*a*EllipticE[1 - b^2/a^2]

62753.3378298691`

Wow. I would say that's as good an approximation as it gets.
Thanks for the reference. :)

Since the eccentricity is not very large, we can sense that the solution
"should" be a little less than the following, which it is.
? 2*10000*[Pi()]
62831.8530717959

= = = = =
Dana DeLouis



JLatham wrote:
Disclaimer: I do not hold a degree in mathematics (heck, I flunked
college
algebra the first time around) and I don't even play one on TV or in
any
Intel advertisements. But...

You got me curious so I went searching for coded solutions to the
problem
and couldn't find any expressed as an Excel formula. What I did
discover is
that a sharp fellow by the name of Srinivasa Ramanujan came up with 2
formulas in 1914 that are now accepted as being very accurate, with the
2nd
effort being the more accurate of the two. All this is shown at
http://en.wikipedia.org/wiki/Circumference

So I worked at implementing his 2nd approximation as an Excel
spreadsheet
formula and I believe I've succeeded:
Given the ellipse's major semi-axis in B1 and
the ellipse's minor semi-axis in B2, then
=(0.5*(B1+B2))*(1+((3*((B1-B2)/(B1+B2))^2)/(10+SQRT((4-(3*((B1-B2)/(B1+B2))^2))))))
gives me results shown on that same Wiki page for the various values of
b
with a value of 10000 for the major semi-axis value.

Since this particular approximation appears to be the Gold Standard of
all
approximations for the circumference of an ellipse, hopefully it will
suit
your needs.


"M" wrote:

Is there a formula to Calculate the Circumference of an ellipse in
excel?

.