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

Function vol_torus

maths/volume.py:482–510  ·  view source on GitHub ↗

r""" | Calculate the Volume of a Torus. | Wikipedia reference: https://en.wikipedia.org/wiki/Torus :return: :math:`2 \pi^2 \cdot torus\_radius \cdot tube\_radius^2` >>> vol_torus(1, 1) 19.739208802178716 >>> vol_torus(4, 3) 710.6115168784338 >>> vol_torus(3, 4)

(torus_radius: float, tube_radius: float)

Source from the content-addressed store, hash-verified

480
481
482def vol_torus(torus_radius: float, tube_radius: float) -> float:
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
489 >>> vol_torus(1, 1)
490 19.739208802178716
491 >>> vol_torus(4, 3)
492 710.6115168784338
493 >>> vol_torus(3, 4)
494 947.4820225045784
495 >>> vol_torus(1.6, 1.6)
496 80.85179925372404
497 >>> vol_torus(0, 0)
498 0.0
499 >>> vol_torus(-1, 1)
500 Traceback (most recent call last):
501 ...
502 ValueError: vol_torus() only accepts non-negative values
503 >>> vol_torus(1, -1)
504 Traceback (most recent call last):
505 ...
506 ValueError: vol_torus() only accepts non-negative values
507 """
508 if torus_radius < 0 or tube_radius < 0:
509 raise ValueError("vol_torus() only accepts non-negative values")
510 return 2 * pow(pi, 2) * torus_radius * pow(tube_radius, 2)
511
512
513def vol_icosahedron(tri_side: float) -> float:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected