python-zeichnen von 3D-cube

Ich versuche, zeichnen Sie einen quader. Tatsächlich fing ich von python-Skript Zeichnung eines Würfels als:

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

points = np.array([[-1, -1, -1],
                  [1, -1, -1 ],
                  [1, 1, -1],
                  [-1, 1, -1],
                  [-1, -1, 1],
                  [1, -1, 1 ],
                  [1, 1, 1],
                  [-1, 1, 1]])


fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

r = [-1,1]

X, Y = np.meshgrid(r, r)

ax.plot_surface(X,Y,1, alpha=0.5)
ax.plot_surface(X,Y,-1, alpha=0.5)
ax.plot_surface(X,-1,Y, alpha=0.5)
ax.plot_surface(X,1,Y, alpha=0.5)
ax.plot_surface(1,X,Y, alpha=0.5)
ax.plot_surface(-1,X,Y, alpha=0.5)

ax.scatter3D(points[:, 0], points[:, 1], points[:, 2])

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

Werden, um ein quader, habe ich multipliziert die Punkte-matrix durch die folgende matrix:

P = 

[[2.06498904e-01  -6.30755443e-07   1.07477548e-03]

 [1.61535574e-06   1.18897198e-01   7.85307721e-06]

 [7.08353661e-02   4.48415767e-06   2.05395893e-01]]

als:

Z = np.zeros((8,3))

for i in range(8):

   Z[i,:] = np.dot(points[i,:],P)

Z = 10.0*Z

Meine Idee ist dann zu vertreten, wie folgt:

ax.scatter3D(Z[:, 0], Z[:, 1], Z[:, 2])

ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

plt.show()

Und das ist, was ich bekomme:

python-zeichnen von 3D-cube

Wie kann ich dann setzen Oberflächen, die auf diese verschiedenen Punkte für die form der quader (in der Art des Würfels oben)?

InformationsquelleAutor rogwar | 2017-07-03

Schreibe einen Kommentar