MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / vol_spherical_cap

Function vol_spherical_cap

maths/volume.py:35–57  ·  view source on GitHub ↗

Calculate the volume of the spherical cap. >>> vol_spherical_cap(1, 2) 5.235987755982988 >>> vol_spherical_cap(1.6, 2.6) 16.621119532592402 >>> vol_spherical_cap(0, 0) 0.0 >>> vol_spherical_cap(-1, 2) Traceback (most recent call last): ... ValueError

(height: float, radius: float)

Source from the content-addressed store, hash-verified

33
34
35def vol_spherical_cap(height: float, radius: float) -> float:
36 """
37 Calculate the volume of the spherical cap.
38
39 >>> vol_spherical_cap(1, 2)
40 5.235987755982988
41 >>> vol_spherical_cap(1.6, 2.6)
42 16.621119532592402
43 >>> vol_spherical_cap(0, 0)
44 0.0
45 >>> vol_spherical_cap(-1, 2)
46 Traceback (most recent call last):
47 ...
48 ValueError: vol_spherical_cap() only accepts non-negative values
49 >>> vol_spherical_cap(1, -2)
50 Traceback (most recent call last):
51 ...
52 ValueError: vol_spherical_cap() only accepts non-negative values
53 """
54 if height < 0 or radius < 0:
55 raise ValueError("vol_spherical_cap() only accepts non-negative values")
56 # Volume is 1/3 pi * height squared * (3 * radius - height)
57 return 1 / 3 * pi * pow(height, 2) * (3 * radius - height)
58
59
60def vol_spheres_intersect(

Callers 2

vol_spheres_intersectFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected