Skip to content

Instantly share code, notes, and snippets.

@mjm522
Last active March 30, 2021 15:54
Show Gist options
  • Save mjm522/6d120b02260b9ad2e53c439511bca26c to your computer and use it in GitHub Desktop.
Save mjm522/6d120b02260b9ad2e53c439511bca26c to your computer and use it in GitHub Desktop.
Draw Cuboid
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
def plot_cuboid(sample_cuboid):
fig = plt.figure(figsize=(12,9))
ax = fig.add_subplot(111, projection='3d')
for pair in sampling_cuboid['plot_pairs']:
start_point = sampling_cuboid['centre_point'] + sampling_cuboid[pair[0]]
end_point = sampling_cuboid['centre_point'] + sampling_cuboid[pair[1]]
ax.plot([start_point[0], end_point[0]],
[start_point[1], end_point[1]],
[start_point[2], end_point[2]], c='k')
plt.show()
h_w = 0.2
h_l = 0.1
h = 0.4
sample_cube = {'centre_point': [0.,0.,0.],
1: [ h_w, -h_l, 0],
2: [ h_w, h_l, 0],
3: [-h_w, h_l, 0],
4: [-h_w, -h_l, 0],
5: [ h_w, -h_l, h],
6: [ h_w, h_l, h],
7: [-h_w, h_l, h],
8: [-h_w, -h_l, h],
'plot_pairs': [(1,2), (2,3), (3,4), (4,1),
(5,6), (6,7), (7,8), (8,5),
(1,5), (2,6), (3,7), (4,8)]}
plot_cuboid(sample_cube)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment