Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions maths/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,35 @@ def vol_torus(torus_radius: float, tube_radius: float) -> float:
return 2 * pow(pi, 2) * torus_radius * pow(tube_radius, 2)


def vol_icosahedron(tri_side: float) -> float:
"""Calculate the Volume of an Icosahedron.
Wikipedia reference: https://en.wikipedia.org/wiki/Regular_icosahedron

>>> from math import isclose
>>> isclose(vol_icosahedron(2.5), 34.088984228514256)
True
>>> isclose(vol_icosahedron(10), 2181.694990624912374)
True
>>> isclose(vol_icosahedron(5), 272.711873828114047)
True
>>> isclose(vol_icosahedron(3.49), 92.740688412033628)
True
>>> vol_icosahedron(0)
0.0
>>> vol_icosahedron(-1)
Traceback (most recent call last):
...
ValueError: vol_icosahedron() only accepts non-negative values
>>> vol_icosahedron(-0.2)
Traceback (most recent call last):
...
ValueError: vol_icosahedron() only accepts non-negative values
"""
if tri_side < 0:
raise ValueError("vol_icosahedron() only accepts non-negative values")
return tri_side**3 * (3 + 5**0.5) * 5 / 12


def main():
"""Print the Results of Various Volume Calculations."""
print("Volumes:")
Expand All @@ -489,6 +518,7 @@ def main():
print(
f"Hollow Circular Cylinder: {vol_hollow_circular_cylinder(1, 2, 3) = }"
) # ~= 28.3
print(f"Icosahedron: {vol_icosahedron(2.5) = }") # ~=34.09


if __name__ == "__main__":
Expand Down