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)
Xc = radius*np.cos(theta_grid) + center[0]
Yc = radius*np.sin(theta_grid) + center[1]
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]:
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])
Xc = radius*np.cos(theta_grid) + center[0]
Yc = radius*np.sin(theta_grid) + center[1]
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:
radius_m = np.linspace(0, radius, 2)
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]:
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([
[0, radius*np.cos(theta[i]), radius*np.cos(theta[i]), 0],
[0, radius*np.cos(theta[i + 1]), radius*np.cos(theta[i + 1]), 0]
]) + center[0]
y1 = np.array([
[0, radius*np.sin(theta[i]), radius*np.sin(theta[i]), 0],
[0, radius*np.sin(theta[i + 1]), radius*np.sin(theta[i + 1]), 0]
]) + 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]:
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])
Xc = radius*np.cos(theta_grid) + center[0]
Yc = radius*np.sin(theta_grid) + center[1]
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):
x1 = np.array([[0, radius*np.cos(theta[i]), radius*np.cos(theta[i]), 0], [0, radius*np.cos(theta[i + 1]), radius*np.cos(theta[i + 1]), 0]])
y1 = np.array([[0, radius*np.sin(theta[i]), radius*np.sin(theta[i]), 0], [0, radius*np.sin(theta[i + 1]), radius*np.sin(theta[i + 1]), 0]])
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]:
In [ ]:
In [ ]:
In [ ]: