Skip to content

Commit f681f44

Browse files
authored
Ellipse perimeter calculation
Updated the perimeter calculation for the Ellipse class to use Ramanujan's approximation
1 parent e2a78d4 commit f681f44

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

geometry/geometry.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ def area(self) -> float:
103103
def perimeter(self) -> float:
104104
"""
105105
>>> Ellipse(5, 10).perimeter
106-
47.12388980384689
106+
48.44222344723793
107107
"""
108-
return math.pi * (self.major_radius + self.minor_radius)
108+
a, b = self.major_radius, self.minor_radius
109+
# uses ramanujans approximation
110+
return math.pi * (3 * (a + b) - ((3 * a + b) * (a + 3 * b)) ** 0.5)
109111

110112

111113
class Circle(Ellipse):

0 commit comments

Comments
 (0)