From 23e0017f67fe0432c53ca65dd79a498c208536fa Mon Sep 17 00:00:00 2001 From: Leonardo Uieda Date: Thu, 22 Feb 2024 09:54:51 -0300 Subject: [PATCH] Add a volume property for the Sphere Nothing fancy, just output the volume. --- boule/_sphere.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/boule/_sphere.py b/boule/_sphere.py index dcfd5c69..462a1b04 100644 --- a/boule/_sphere.py +++ b/boule/_sphere.py @@ -97,6 +97,8 @@ class Sphere: 0 >>> print(sphere.thirdflattening) 0 + >>> print(f"{sphere.volume:.10f} m³") + 4.1887902048 m³ """ @@ -174,6 +176,15 @@ def first_eccentricity(self): """ return 0 + @property + def volume(self): + r""" + The volume of the sphere. + Definition: :math:`V = \dfrac{4}{3} \pi r^3`. + Units: :math:`m^3`. + """ + return (4 / 3 * np.pi) * self.radius**3 + def normal_gravity(self, latitude, height, si_units=False): r""" Normal gravity of the sphere at the given latitude and height.