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

Function vol_sphere

maths/volume.py:319–342  ·  view source on GitHub ↗

r""" | Calculate the Volume of a Sphere. | Wikipedia reference: https://en.wikipedia.org/wiki/Sphere :return: :math:`\frac{4}{3} \cdot \pi \cdot r^3` >>> vol_sphere(5) 523.5987755982989 >>> vol_sphere(1) 4.1887902047863905 >>> vol_sphere(1.6) 17.15728467880506

(radius: float)

Source from the content-addressed store, hash-verified

317
318
319def vol_sphere(radius: float) -> float:
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
326 >>> vol_sphere(5)
327 523.5987755982989
328 >>> vol_sphere(1)
329 4.1887902047863905
330 >>> vol_sphere(1.6)
331 17.15728467880506
332 >>> vol_sphere(0)
333 0.0
334 >>> vol_sphere(-1)
335 Traceback (most recent call last):
336 ...
337 ValueError: vol_sphere() only accepts non-negative values
338 """
339 if radius < 0:
340 raise ValueError("vol_sphere() only accepts non-negative values")
341 # Volume is 4/3 * pi * radius cubed
342 return 4 / 3 * pi * pow(radius, 3)
343
344
345def vol_hemisphere(radius: float) -> float:

Callers 3

vol_spheres_intersectFunction · 0.85
vol_spheres_unionFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected