11"""
22Find the volume of various shapes.
3+
34* https://en.wikipedia.org/wiki/Volume
45* https://en.wikipedia.org/wiki/Spherical_cap
56"""
1213def vol_cube (side_length : float ) -> float :
1314 """
1415 Calculate the Volume of a Cube.
16+
1517 >>> vol_cube(1)
1618 1.0
1719 >>> vol_cube(3)
@@ -33,6 +35,7 @@ def vol_cube(side_length: float) -> float:
3335def vol_spherical_cap (height : float , radius : float ) -> float :
3436 """
3537 Calculate the volume of the spherical cap.
38+
3639 >>> vol_spherical_cap(1, 2)
3740 5.235987755982988
3841 >>> vol_spherical_cap(1.6, 2.6)
@@ -57,20 +60,29 @@ def vol_spherical_cap(height: float, radius: float) -> float:
5760def vol_spheres_intersect (
5861 radius_1 : float , radius_2 : float , centers_distance : float
5962) -> float :
60- """
63+ r """
6164 Calculate the volume of the intersection of two spheres.
65+
6266 The intersection is composed by two spherical caps and therefore its volume is the
63- sum of the volumes of the spherical caps. First, it calculates the heights (h1, h2)
64- of the spherical caps, then the two volumes and it returns the sum.
67+ sum of the volumes of the spherical caps.
68+ First, it calculates the heights :math:`(h_1, h_2)` of the spherical caps,
69+ then the two volumes and it returns the sum.
6570 The height formulas are
66- h1 = (radius_1 - radius_2 + centers_distance)
67- * (radius_1 + radius_2 - centers_distance)
68- / (2 * centers_distance)
69- h2 = (radius_2 - radius_1 + centers_distance)
70- * (radius_2 + radius_1 - centers_distance)
71- / (2 * centers_distance)
72- if centers_distance is 0 then it returns the volume of the smallers sphere
73- :return vol_spherical_cap(h1, radius_2) + vol_spherical_cap(h2, radius_1)
71+
72+ .. math::
73+ h_1 = \frac{(radius_1 - radius_2 + centers\_distance)
74+ \cdot (radius_1 + radius_2 - centers\_distance)}
75+ {2 \cdot centers\_distance}
76+
77+ h_2 = \frac{(radius_2 - radius_1 + centers\_distance)
78+ \cdot (radius_2 + radius_1 - centers\_distance)}
79+ {2 \cdot centers\_distance}
80+
81+ if `centers_distance` is 0 then it returns the volume of the smallers sphere
82+
83+ :return: ``vol_spherical_cap`` (:math:`h_1`, :math:`radius_2`)
84+ + ``vol_spherical_cap`` (:math:`h_2`, :math:`radius_1`)
85+
7486 >>> vol_spheres_intersect(2, 2, 1)
7587 21.205750411731103
7688 >>> vol_spheres_intersect(2.6, 2.6, 1.6)
@@ -112,14 +124,18 @@ def vol_spheres_intersect(
112124def vol_spheres_union (
113125 radius_1 : float , radius_2 : float , centers_distance : float
114126) -> float :
115- """
127+ r """
116128 Calculate the volume of the union of two spheres that possibly intersect.
117- It is the sum of sphere A and sphere B minus their intersection.
118- First, it calculates the volumes (v1, v2) of the spheres,
119- then the volume of the intersection (i) and it returns the sum v1+v2-i.
120- If centers_distance is 0 then it returns the volume of the larger sphere
121- :return vol_sphere(radius_1) + vol_sphere(radius_2)
122- - vol_spheres_intersect(radius_1, radius_2, centers_distance)
129+
130+ It is the sum of sphere :math:`A` and sphere :math:`B` minus their intersection.
131+ First, it calculates the volumes :math:`(v_1, v_2)` of the spheres,
132+ then the volume of the intersection :math:`i` and
133+ it returns the sum :math:`v_1 + v_2 - i`.
134+ If `centers_distance` is 0 then it returns the volume of the larger sphere
135+
136+ :return: ``vol_sphere`` (:math:`radius_1`) + ``vol_sphere`` (:math:`radius_2`)
137+ - ``vol_spheres_intersect``
138+ (:math:`radius_1`, :math:`radius_2`, :math:`centers\_distance`)
123139
124140 >>> vol_spheres_union(2, 2, 1)
125141 45.814892864851146
@@ -157,7 +173,9 @@ def vol_spheres_union(
157173def vol_cuboid (width : float , height : float , length : float ) -> float :
158174 """
159175 Calculate the Volume of a Cuboid.
160- :return multiple of width, length and height
176+
177+ :return: multiple of `width`, `length` and `height`
178+
161179 >>> vol_cuboid(1, 1, 1)
162180 1.0
163181 >>> vol_cuboid(1, 2, 3)
@@ -185,10 +203,12 @@ def vol_cuboid(width: float, height: float, length: float) -> float:
185203
186204
187205def vol_cone (area_of_base : float , height : float ) -> float :
188- """
189- Calculate the Volume of a Cone.
190- Wikipedia reference: https://en.wikipedia.org/wiki/Cone
191- :return (1/3) * area_of_base * height
206+ r"""
207+ | Calculate the Volume of a Cone.
208+ | Wikipedia reference: https://en.wikipedia.org/wiki/Cone
209+
210+ :return: :math:`\frac{1}{3} \cdot area\_of\_base \cdot height`
211+
192212 >>> vol_cone(10, 3)
193213 10.0
194214 >>> vol_cone(1, 1)
@@ -212,10 +232,12 @@ def vol_cone(area_of_base: float, height: float) -> float:
212232
213233
214234def vol_right_circ_cone (radius : float , height : float ) -> float :
215- """
216- Calculate the Volume of a Right Circular Cone.
217- Wikipedia reference: https://en.wikipedia.org/wiki/Cone
218- :return (1/3) * pi * radius^2 * height
235+ r"""
236+ | Calculate the Volume of a Right Circular Cone.
237+ | Wikipedia reference: https://en.wikipedia.org/wiki/Cone
238+
239+ :return: :math:`\frac{1}{3} \cdot \pi \cdot radius^2 \cdot height`
240+
219241 >>> vol_right_circ_cone(2, 3)
220242 12.566370614359172
221243 >>> vol_right_circ_cone(0, 0)
@@ -237,10 +259,12 @@ def vol_right_circ_cone(radius: float, height: float) -> float:
237259
238260
239261def vol_prism (area_of_base : float , height : float ) -> float :
240- """
241- Calculate the Volume of a Prism.
242- Wikipedia reference: https://en.wikipedia.org/wiki/Prism_(geometry)
243- :return V = Bh
262+ r"""
263+ | Calculate the Volume of a Prism.
264+ | Wikipedia reference: https://en.wikipedia.org/wiki/Prism_(geometry)
265+
266+ :return: :math:`V = B \cdot h`
267+
244268 >>> vol_prism(10, 2)
245269 20.0
246270 >>> vol_prism(11, 1)
@@ -264,10 +288,12 @@ def vol_prism(area_of_base: float, height: float) -> float:
264288
265289
266290def vol_pyramid (area_of_base : float , height : float ) -> float :
267- """
268- Calculate the Volume of a Pyramid.
269- Wikipedia reference: https://en.wikipedia.org/wiki/Pyramid_(geometry)
270- :return (1/3) * Bh
291+ r"""
292+ | Calculate the Volume of a Pyramid.
293+ | Wikipedia reference: https://en.wikipedia.org/wiki/Pyramid_(geometry)
294+
295+ :return: :math:`\frac{1}{3} \cdot B \cdot h`
296+
271297 >>> vol_pyramid(10, 3)
272298 10.0
273299 >>> vol_pyramid(1.5, 3)
@@ -291,10 +317,12 @@ def vol_pyramid(area_of_base: float, height: float) -> float:
291317
292318
293319def vol_sphere (radius : float ) -> float :
294- """
295- Calculate the Volume of a Sphere.
296- Wikipedia reference: https://en.wikipedia.org/wiki/Sphere
297- :return (4/3) * pi * r^3
320+ r"""
321+ | Calculate the Volume of a Sphere.
322+ | Wikipedia reference: https://en.wikipedia.org/wiki/Sphere
323+
324+ :return: :math:`\frac{4}{3} \cdot \pi \cdot r^3`
325+
298326 >>> vol_sphere(5)
299327 523.5987755982989
300328 >>> vol_sphere(1)
@@ -315,10 +343,13 @@ def vol_sphere(radius: float) -> float:
315343
316344
317345def vol_hemisphere (radius : float ) -> float :
318- """Calculate the volume of a hemisphere
319- Wikipedia reference: https://en.wikipedia.org/wiki/Hemisphere
320- Other references: https://www.cuemath.com/geometry/hemisphere
321- :return 2/3 * pi * radius^3
346+ r"""
347+ | Calculate the volume of a hemisphere
348+ | Wikipedia reference: https://en.wikipedia.org/wiki/Hemisphere
349+ | Other references: https://www.cuemath.com/geometry/hemisphere
350+
351+ :return: :math:`\frac{2}{3} \cdot \pi \cdot radius^3`
352+
322353 >>> vol_hemisphere(1)
323354 2.0943951023931953
324355 >>> vol_hemisphere(7)
@@ -339,9 +370,12 @@ def vol_hemisphere(radius: float) -> float:
339370
340371
341372def vol_circular_cylinder (radius : float , height : float ) -> float :
342- """Calculate the Volume of a Circular Cylinder.
343- Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder
344- :return pi * radius^2 * height
373+ r"""
374+ | Calculate the Volume of a Circular Cylinder.
375+ | Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder
376+
377+ :return: :math:`\pi \cdot radius^2 \cdot height`
378+
345379 >>> vol_circular_cylinder(1, 1)
346380 3.141592653589793
347381 >>> vol_circular_cylinder(4, 3)
@@ -368,7 +402,9 @@ def vol_circular_cylinder(radius: float, height: float) -> float:
368402def vol_hollow_circular_cylinder (
369403 inner_radius : float , outer_radius : float , height : float
370404) -> float :
371- """Calculate the Volume of a Hollow Circular Cylinder.
405+ """
406+ Calculate the Volume of a Hollow Circular Cylinder.
407+
372408 >>> vol_hollow_circular_cylinder(1, 2, 3)
373409 28.274333882308138
374410 >>> vol_hollow_circular_cylinder(1.6, 2.6, 3.6)
@@ -405,8 +441,9 @@ def vol_hollow_circular_cylinder(
405441
406442
407443def vol_conical_frustum (height : float , radius_1 : float , radius_2 : float ) -> float :
408- """Calculate the Volume of a Conical Frustum.
409- Wikipedia reference: https://en.wikipedia.org/wiki/Frustum
444+ """
445+ | Calculate the Volume of a Conical Frustum.
446+ | Wikipedia reference: https://en.wikipedia.org/wiki/Frustum
410447
411448 >>> vol_conical_frustum(45, 7, 28)
412449 48490.482608158454
@@ -443,9 +480,12 @@ def vol_conical_frustum(height: float, radius_1: float, radius_2: float) -> floa
443480
444481
445482def vol_torus (torus_radius : float , tube_radius : float ) -> float :
446- """Calculate the Volume of a Torus.
447- Wikipedia reference: https://en.wikipedia.org/wiki/Torus
448- :return 2pi^2 * torus_radius * tube_radius^2
483+ r"""
484+ | Calculate the Volume of a Torus.
485+ | Wikipedia reference: https://en.wikipedia.org/wiki/Torus
486+
487+ :return: :math:`2 \pi^2 \cdot torus\_radius \cdot tube\_radius^2`
488+
449489 >>> vol_torus(1, 1)
450490 19.739208802178716
451491 >>> vol_torus(4, 3)
@@ -471,8 +511,9 @@ def vol_torus(torus_radius: float, tube_radius: float) -> float:
471511
472512
473513def vol_icosahedron (tri_side : float ) -> float :
474- """Calculate the Volume of an Icosahedron.
475- Wikipedia reference: https://en.wikipedia.org/wiki/Regular_icosahedron
514+ """
515+ | Calculate the Volume of an Icosahedron.
516+ | Wikipedia reference: https://en.wikipedia.org/wiki/Regular_icosahedron
476517
477518 >>> from math import isclose
478519 >>> isclose(vol_icosahedron(2.5), 34.088984228514256)
0 commit comments