# cylinder-geometry.ipynb

In [1]:
import matplotlib.pyplot as plt
import numpy as np
# %matplotlib widget

In [2]:
radius = 10
length = 5
center = np.array([0, 0, 0])
z = np.linspace(-length/2, length/2, 50)
theta = np.linspace(0, 2*np.pi, 50)
theta_grid, Zc = np.meshgrid(theta, z)

Zc = Zc + center[2]

In [3]:
fig = plt.figure(figsize = (6, 6))
ax = plt.axes(projection='3d', box_aspect = (1, 1, 1))
ax.plot_surface(Xc, Yc, Zc, alpha=0.2)

Out[3]:
<mpl_toolkits.mplot3d.art3d.Poly3DCollection at 0x190c238fc40>
In [4]:
radius = 3
length = 5
sides = 100
zs = np.linspace(-length/2, length/2, 2)
theta = np.linspace(0, 2*np.pi, sides + 1)
theta_grid, Zc = np.meshgrid(theta, zs)

center = np.array([0, 0, 0])

Zc = Zc + center[2]

In [5]:
fig = plt.figure(figsize = (6, 6))
ax = plt.axes(projection='3d', box_aspect = (1, 1, 1))

ax.plot(*center, color = 'red', marker = 'o')
ax.text(center[0] + 0.25, center[1] + 0.25, center[2] + 0.25, s = 'O', fontsize = 12)

# plot_circle([0, 0, length/2], radius, theta)
# plot_circle([0, 0, -length/2], radius, theta)

for z in zs:
x1 = np.outer(radius_m, np.cos(theta)) + center[0]
y1 = np.outer(radius_m, np.sin(theta)) + center[1]
z1 = np.zeros(y1.shape) + z + center[2]
ax.plot_surface(x1, y1, z1, color = 'red', alpha = 0.5)

ax.plot_surface(Xc, Yc, Zc, color = 'blue', alpha = 0.5)

ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
ax.set_zlim(-5, 5)

Out[5]:
(-5.0, 5.0)
In [ ]:


In [ ]:


In [6]:
fig = plt.figure(figsize = (6, 6))
ax = plt.axes(projection='3d', box_aspect = (1, 1, 1))

ax.plot(*center, color = 'red', marker = 'o')
ax.text(center[0] + 0.25, center[1] + 0.25, center[2] + 0.25, s = 'O', fontsize = 12)

for i in range(len(theta) - 1):
x1 = np.array([
]) + center[0]
y1 = np.array([
]) + center[1]
z1 =  np.array([
[length/2, length/2, -length/2, -length/2],
[length/2, length/2, -length/2, -length/2],
]) + center[2]

ax.plot_surface(x1, y1, z1, color = 'red', alpha = 0.5)

# ax.plot_surface(Xc, Yc, Zc, color = 'blue', alpha = 0.5)

ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
ax.set_zlim(-5, 5)

Out[6]:
(-5.0, 5.0)

## Got the spiral pattern

In [7]:
radius = 3
length = 5
sides = 10
zs = np.linspace(-length/2, length/2, 2)
theta = np.linspace(0, 2*np.pi, sides + 1)
theta_grid, Zc = np.meshgrid(theta, zs)

center = np.array([0, 0, 0])

Zc = Zc + center[2]

In [8]:
fig = plt.figure(figsize = (6, 6))
ax = plt.axes(projection='3d', box_aspect = (1, 1, 1))
for i in range(len(theta) - 1):
z1 =  np.array([[length/2, length/2, length/2, length/2], [-length/2, -length/2, -length/2, -length/2],])
ax.plot_surface(x1, y1, z1)
ax.set_xlim(-5, 5)
ax.set_ylim(-5, 5)
ax.set_zlim(-5, 5)

Out[8]:
(-5.0, 5.0)
In [ ]:


In [ ]:


In [ ]: