@@ -509,6 +509,30 @@ def vol_torus(torus_radius: float, tube_radius: float) -> float:
509509 raise ValueError ("vol_torus() only accepts non-negative values" )
510510 return 2 * pow (pi , 2 ) * torus_radius * pow (tube_radius , 2 )
511511
512+ def vol_octahedron (oct_side : float ) -> float :
513+ """
514+ | Calculate the Volume of an Octahedron.
515+ | Wikipedia reference: https://en.wikipedia.org/wiki/Regular_octahedron
516+
517+ >>> from math import isclose
518+ >>> isclose(vol_octahedron(2.5), 7.36569563735987)
519+ True
520+ >>> isclose(vol_octahedron(10), 471.40452079103168)
521+ True
522+ >>> isclose(vol_octahedron(5), 58.92556509887896)
523+ True
524+ >>> isclose(vol_octahedron(3.5), 20.21146882891548)
525+ True
526+ >>> vol_octahedron(0)
527+ 0.0
528+ >>> vol_octahedron(-1)
529+ Traceback (most recent call last):
530+ ...
531+ ValueError: vol_octahedron() only accepts non-negative values
532+ """
533+ if oct_side < 0 :
534+ raise ValueError ("vol_octahedron() only accepts non-negative values" )
535+ return oct_side ** 3 * 2 ** 0.5 / 3
512536
513537def vol_icosahedron (tri_side : float ) -> float :
514538 """
@@ -560,6 +584,7 @@ def main():
560584 print (
561585 f"Hollow Circular Cylinder: { vol_hollow_circular_cylinder (1 , 2 , 3 ) = } "
562586 ) # ~= 28.3
587+ print (f"Octahedron: { vol_octahedron (2.5 ) = } " ) # ~=7.37
563588 print (f"Icosahedron: { vol_icosahedron (2.5 ) = } " ) # ~=34.09
564589
565590
0 commit comments