Home |
Search |
Today's Posts |
#14
![]()
Posted to microsoft.public.excel.misc
|
|||
|
|||
![]()
'special case: if majorAxis=minorAxis, then it's a circle
If majorAxis = minorAxis Then Oops! Me bad. You talked me into changing it. :( When b=a, then the equation is just 2*a*Pi anyway. So, the above is not necessary either. Sub TestIt() '// Ellipse Perimeter Debug.Print Perimeter(10000, 9975) Debug.Print Perimeter(9975, 10000) Debug.Print Debug.Print Perimeter(10000, 10000) Debug.Print 2 * [Pi()] * 10000 End Sub Returns: 62753.3378298691 62753.3378298691 62831.8530717959 62831.8530717959 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 = = = = = = Dana DeLouis Dana DeLouis wrote: 'just to be technical, if minor axis major axis, swap ... ((majorAxis - minorAxis) / (majorAxis + minorAxis)) ^ 2 Hi. Just to mention if interested. If I am not mistaken, one does not need to swap the variables. This is because (majorAxis - minorAxis) gets squared. The result in the same positive value either way. The code below is the same thing just to demonstrate. Sub TestIt() '// Ellipse Perimeter Debug.Print Perimeter(10000, 9975) Debug.Print Perimeter(9975, 10000) End Sub Returns: 62753.3378298691 62753.3378298691 Function Perimeter(a, b) Dim k As Double If a = b Then Perimeter = 2 * [Pi()] * a Else k = 3 * ((a - b) / (a + b)) ^ 2 Perimeter = (a + b) * (1 + k / (10 + Sqr(4 - k))) * [Pi()] End If End Function = = = = = = HTH Dana DeLouis JLatham wrote: With some great guidance from David Biddulph and Dana DeLouis I've modified the functions to calculate the actual (approximated) perimeter/circumference of the ellipse, and have left the perimetric radius as a 'way point" in the process should anyone need that value. The previous worksheet formula was revised in the comment in these functions to also calculate the approximated perimeter. 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 'Acknowledgment: Thanks to David Biddulph and Dana DeLouis for ' helping me realize the difference between parimetric radius and circumference ' 'worksheet equivalent formula where ' B1 holds the majorAxis value and ' B2 holds the minorAxis value '=(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)))))) * (2 * Pi()) ' 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 'calculate the perimetric radius Ram2Perimeter = (0.5 * majorPlusMinor) * _ (1 + ((3 * quotentSquared / _ (10 + Sqr((4 - 3 * quotentSquared)))))) 'calculate the circumference [ 4 x Atn(1) = Pi ] Ram2Perimeter = Ram2Perimeter * 2 * (4 * Atn(1)) 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 'Acknowledgment: Thanks to David Biddulph and Dana DeLouis for ' helping me realize the difference between parimetric radius and circumference ' 'worksheet equivalent formula where ' B1 holds the majorAxis value and ' B2 holds the minorAxis value '=(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)))))) * (2 * Pi()) ' 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 'calculate the perimetric radius Ram2Perimeter2 = (0.5 * (majorAxis + minorAxis)) * _ (1 + ((3 * (((majorAxis - minorAxis) / (majorAxis + minorAxis)) ^ 2) / _ (10 + Sqr((4 - 3 * (((majorAxis - minorAxis) / (majorAxis + minorAxis)) ^ 2))))))) 'calculate the circumference [ 4 x Atn(1) = Pi ] Ram2Perimeter2 = Ram2Perimeter2 * 2 * (4 * Atn(1)) On Error GoTo 0 Exit Function RamanujanCir2Err: Err.Clear Ram2Perimeter2 = -1 End Function "M" wrote: Is there a formula to Calculate the Circumference of an ellipse in excel? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How to calculate | Excel Discussion (Misc queries) | |||
one row won't calculate | Excel Discussion (Misc queries) | |||
calculate time does not calculate | Excel Discussion (Misc queries) | |||
circumference formula | Excel Discussion (Misc queries) | |||
Graphing ellipse equation | Charts and Charting in Excel |