0

Can someone please explain to me or show me how to create a 3D wireframe polygon house using 2D line plotting commands in Python? I know I need a set of vertices and connect them to be 2D lines and then plot them. I'm just not completely sure how to do it.

ElizabethC
  • 41
  • 4
  • Welcome to stackoverflow. You probably would like to read [ask] as you were quite lucky that someone took the time to answer your question, which is otherwise not according to the guidelines. Next time asking, it would be good to include a clear problem description from which it becomes clear what you have tried and at which point you encounter the problem. – ImportanceOfBeingErnest Oct 02 '17 at 08:53

1 Answers1

1

Based on the excellent answer for various 3D shapes, you could do something like,

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
from itertools import product, combinations


fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_aspect("equal")

# draw cube 
r = [-1, 1]
points = list(product(r, r, r))

#Add roof
points.append([0., 1.5, -1.])
points.append([0., 1.5, 1.])

#Convert to array
points = np.array(points)

#Plot
ax.scatter(points[:,0], points[:,1], points[:,2])
for s, e in combinations(points, 2):
    #All diagonals will be greater than 2
    if np.sum(np.abs(s-e)) <= 2:
        ax.plot3D(*zip(s, e), color="k")
plt.show()

which then looks like this,

enter image description here

Ed Smith
  • 12,716
  • 2
  • 43
  • 55