Login / Get an account Logout
  • view
  • history

test.py

import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
corners = [ [-1,0.5,0.5], [+1,0.5,0.5], [0,-0.5,0.5], [0,0.5,-0.5] ]
face1 = [ corners[0], corners[1], corners[2] ] 
face2 = [ corners[0], corners[1], corners[3] ] 
face3 = [ corners[0], corners[2], corners[3] ] 
face4 = [ corners[1], corners[2], corners[3] ] 
vertices = np.array(face1+face2+face3+face4,dtype=float)
print(vertices)
ob = Poly3DCollection(vertices, linewidths=1, alpha=0.2)
ob.set_facecolor( [0.5, 0.5, 1] )
ob.set_edgecolor([0,0,0])
plt.ion()
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
plt.show()
ax.add_collection3d(ob)
translation = np.array( [ 1, 0, 0 ], dtype=float ) 
v2 = vertices + translation
print(v2)
ob2 = Poly3DCollection(v2, linewidths=1, alpha=0.2)
ob2.set_facecolor( [0.5, 1, 0.5] )
ob2.set_edgecolor([0,0,0])
ax.add_collection3d(ob2)
theta = np.pi/6
R = np.array( [ [ np.cos(theta), -np.sin(theta), 0 ],
                [ np.sin(theta),  np.cos(theta), 0 ],
                [ 0,              0,             1 ] ], dtype=float )
v3 = np.matmul(vertices,R)
print(v3)
ob3 = Poly3DCollection(v3, linewidths=1, alpha=0.2)
ob3.set_facecolor( [1, 0.5, 0.5] )
ob3.set_edgecolor([0,0,0])
ax.add_collection3d(ob3)
powered by gitit
Site
  • Front page
  • All pages
  • Categories
  • Random page
  • Recent activity
  • Upload a file
  • Help
This page
  • Raw page source
  • Printable version
  • Delete this page