We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e2a78d4 commit f0171a3Copy full SHA for f0171a3
geometry/geometry.py
@@ -103,9 +103,12 @@ def area(self) -> float:
103
def perimeter(self) -> float:
104
"""
105
>>> Ellipse(5, 10).perimeter
106
- 47.12388980384689
+ 48.44210548835644
107
108
- return math.pi * (self.major_radius + self.minor_radius)
+ a, b = self.major_radius, self.minor_radius
109
+ # Use Ramanujan's first approximation for ellipse perimeter
110
+ # https://en.wikipedia.org/wiki/Perimeter_of_an_ellipse#First_approximation
111
+ return math.pi * (3 * (a + b) - ((3 * a + b) * (a + 3 * b)) ** 0.5)
112
113
114
class Circle(Ellipse):
0 commit comments