%matplotlib inline
from IPython.core.pylabtools import figsize
from matplotlib import pyplot as plt
import matplotlib as mpl
import numpy as np
import pandas as pd
from mpl_toolkits import mplot3d

Matplotlib Settings

figsize(11, 7)
mpl.rcParams['lines.linewidth'] = 2
mpl.rcParams['axes.edgecolor'] = "#bcbcbc"
mpl.rcParams['patch.linewidth'] = 0.5
mpl.rcParams['legend.fancybox'] = True
mpl.rcParams['axes.facecolor'] = "#eeeeee"
mpl.rcParams['axes.labelsize'] = "large"
mpl.rcParams['axes.grid'] = True
mpl.rcParams['patch.edgecolor'] = "#eeeeee"
mpl.rcParams['axes.titlesize'] = "x-large"
mpl.rcParams['axes.grid'] = True
mpl.rcParams['grid.linestyle'] = "dotted"

Sphere:

Surface Area: $4\pi a^{2}$
Volume: $\frac{4}{3}\pi a^{3}$

# Sphere
class Sphere(object):
    @staticmethod
    def area(r):
        return 4. * np.pi * r**2
    
    @staticmethod
    def volume(r):
        return (4. * np.pi * r**3)/3.
    
    @staticmethod
    def a_from_area(a):
        return np.power(a/(4 * np.pi), 1/2)
    
    @staticmethod
    def a_from_vol(v):
        return np.power((3 * v)/(4 * np.pi),1/3)

Cube:

Surface Area: $6 a^{2}$
Volume: $a^{3}$

# Cube
class Cube(object):
    @staticmethod
    def area(r):
        return 6 * r**2
    
    @staticmethod
    def volume(r):
        return r**3
    
    @staticmethod
    def a_from_area(a):
        return np.power(a/6., 1/2)
    
    @staticmethod
    def a_from_vol(v):
        return np.power(v,1/3)

Cylinder:

Surface Area: $4\pi r h$
Volume: $\pi r h$

# Cylinder
class Cylinder(object):
    @staticmethod
    def area(r):
        return 4. * np.pi * r**2
    
    @staticmethod
    def volume(r):
        return np.pi * r**3
    
    @staticmethod
    def a_from_area(a):
        return np.power(a/(4 * np.pi), 1/2)
    
    @staticmethod
    def a_from_vol(v):
        return np.power(v/np.pi,1/3)

Cone:

Surface Area: $\pi r (r + \sqrt{h^{2}+r^{2}})$
Volume: $\frac{1}{3}\pi r^{2}h$

# Cone
class Cone(object):
    @staticmethod
    def area(r):
        return np.pi * r**2 * 2.414213562373095
    
    @staticmethod
    def volume(r):
        return (np.pi * r**3)/3.
    
    @staticmethod
    def a_from_area(a):
        return np.power(a/(np.pi * 2.414213562373095), 1/2)
    
    @staticmethod
    def a_from_vol(v):
        return np.power((3 * v)/np.pi,1/3)

Tetrahedron:

Surface Area: $\sqrt{3} a^{2}$
Volume: $\frac{\sqrt{2}a^{3}}{12}$

# Tetrahedron
class Tetrahedron(object):
    @staticmethod
    def area(r):
        return 1.73205080756 * r**2
    
    @staticmethod
    def volume(r):
        return (1.414213562373095 * r**3) / 12.
    
    @staticmethod
    def a_from_area(a):
        return np.power(a/1.73205080756, 1/2)
    
    @staticmethod
    def a_from_vol(v):
        return np.power((12 * v)/1.414213562373095,1/3)

Octahedron:

Surface Area: $2{\sqrt{3}}a^{2}$
Volume: $\frac{1}{3}\sqrt{2} a^{3}$

# Octahedron
class Octahedron(object):
    @staticmethod
    def area(r):
        return 2 * 1.73205080756 * r**2
    
    @staticmethod
    def volume(r):
        return (1.414213562373095 * r**3) / 3.
    
    @staticmethod
    def a_from_area(a):
        return np.power(a/(2 * 1.73205080756), 1/2)
    
    @staticmethod
    def a_from_vol(v):
        return np.power((3 * v)/1.414213562373095,1/3)

Dodecahedron:

Surface Area: $3{\sqrt{25+10{\sqrt{5}}}}a^{2}$
Volume: ${\frac{1}{4}}(15+7{\sqrt{5}})a^{3}$

# Dodecahedron
class Dodecahedron(object):
    @staticmethod
    def area(r):
        return 3 * np.power(25 + 10*np.power(5,1/2),1/2) * r**2
    
    @staticmethod
    def volume(r):
        return ((7 * np.power(5, 1/2) + 15) * r**3)/4.
    
    @staticmethod
    def a_from_area(a):
        return np.power(a/(3 * np.power(25 + 10*np.power(5,1/2),1/2)), 1/2)
    
    @staticmethod
    def a_from_vol(v):
        return np.power((4 * v)/(7 * np.power(5, 1/2) + 15),1/3)

Capsule:

Surface Area: $4\pi a^{2}+2\pi a2a=8\pi a^{2}$
Volume: $\frac{4\pi a^{3}}{3}+\pi a^{2}
2a=\frac{10\pi a^{3}}{3}$

# Capsule
class Capsule(object):
    @staticmethod
    def area(r):
        return 8 * np.pi * r**2
    
    @staticmethod
    def volume(r):
        return (10 * np.pi * r**3) / 3.
    
    @staticmethod
    def a_from_area(a):
        return np.power(a/(8 * np.pi), 1/2)
    
    @staticmethod
    def a_from_vol(v):
        return np.power((3 * v)/(10 * np.pi),1/3)

Icosahedron:

Surface Area: $5{\sqrt{3}}a^{2}$
Volume: ${\frac{5}{12}}(3+{\sqrt{5}})a^{3}$

# Icosahedron
class Icosahedron(object):
    @staticmethod
    def area(r):
        return 5 * 1.73205080756 * r**2
    
    @staticmethod
    def volume(r):
        return (5 * 5.23606797749979 * r**3)/12
    
    @staticmethod
    def a_from_area(a):
        return np.power(a/(5 * 1.73205080756), 1/2)
    
    @staticmethod
    def a_from_vol(v):
        return np.power((12 * v)/(5 * 5.23606797749979),1/3)
solids = [Sphere, Cube, Cylinder, Cone, Tetrahedron, Dodecahedron, Capsule, Icosahedron]
for x in solids:
    print(x.__name__)
Sphere
Cube
Cylinder
Cone
Tetrahedron
Dodecahedron
Capsule
Icosahedron
a = np.arange(1000)
color_palette = ["#191970","#006400","#ff4500","#ffd700","#00ff00","#00ffff","#ff00ff","#ffb6c1"]
plt.figure()
for i, solid in enumerate(solids):
    plt.plot(a, solid.area(a), c=color_palette[i], label=solid.__name__)
plt.xlim(0, 1000)
plt.ylim(0)
plt.xlabel("Characteristic Length $a$")
plt.ylabel("Surface Area")
plt.title("Growth of Surface Area w/ Characteristic Length")
plt.legend()
plt.show()

Growth of Surface Area w/ Characteristic Length

plt.figure()
for i, solid in enumerate(solids):
    plt.plot(a, solid.volume(a), c=color_palette[i], label=solid.__name__)
plt.xlim(0, 1000)
plt.ylim(0)
plt.xlabel("Characteristic Length $a$")
plt.ylabel("Volume")
plt.title("Growth of Volume w/ Characteristic Length")
plt.legend()
plt.show()

Growth of Volume w/ Characteristic Length

plt.figure()
for i, solid in enumerate(solids):
    plt.plot(a, solid.area(solid.a_from_vol(a)), c=color_palette[i], label=solid.__name__)
plt.xlim(0, 1000)
plt.ylim(0)
plt.xlabel("Volume $V$")
plt.ylabel("Surface Area of Solid")
plt.title("Growth of Volume w/ Surface Area")
plt.legend()
plt.show()

Growth of Volume w/ Surface Area

plt.figure()
for i, solid in enumerate(solids):
    plt.plot(a, solid.volume(solid.a_from_area(a)), c=color_palette[i], label=solid.__name__)
plt.xlim(0, 1000)
plt.ylim(0)
plt.xlabel("Surface Area $A$")
plt.ylabel("Volume of Solid")
plt.title("Growth of Surface Area w/ Volume")
plt.legend()
plt.show()

Growth of Surface Area w/ Volume

fig = plt.figure()
ax = plt.axes(projection='3d')
for i, solid in enumerate(solids):
    ax.plot3D(a, solid.area(a), solid.volume(a), c=color_palette[i], label=solid.__name__)
ax.set_xlabel("Characteristic Length $a$")
ax.set_ylabel("Surface Area $A$")
ax.set_zlabel("Volume of Solid")
plt.title("Growth of Volume w/ Surface Area")
plt.legend()
plt.show()

Growth of Volume w/ Surface Area