|
From: <cl...@br...> - 2014-03-26 11:48:18
|
Dear colleagues, Exploring the 3D support for plotting a simple trapezoid isosceles based on eight locations with x,y,z (imagine a water tank). When doing a manual selection of the collections that defines each surface plane, the drawing works well (see a sample below). Watching for a more automated process that could work with a complex surface based on any Polygons. My question: Is there an algorithm, or function in Numpy or Matplotlib that identifies the quartet of each plane in the sample below? I've tried to apply Numpy function "combinations", but it generates too many collections. Thanks in advance for your hint to optimize this drawing with the Matplotlib with Poly3DCollection Sample Code ----------- from mpl_toolkits.mplot3d import Axes3D from mpl_toolkits.mplot3d.art3d import Poly3DCollection from mpl_toolkits.mplot3d.art3d import Line3DCollection import matplotlib.pyplot as plt from matplotlib import cm import matplotlib.colors as colors from numpy import random fig = plt.figure() ax = Axes3D(fig) # for random color settings color = colors.rgb2hex(random.rand(3)) # blue color color = 'b' #mypoly = [[2, 0, -1], [2, 0, 1], [4, 0, 1], [4, 0, -1], [0, 4, -2], [0, 4, 2], [6, 4, 2], [6, 4, -2]] # A B C D E F G H # Colections for drawing 3D plot with polygon (each plane defined separately) #plane a: A,E,H,D #plane b: A,E,F,B #plane c: B,F,G,C #plane d: C,G,H,D #plane e: E,F,G,H #plane f: A,B,C,D #plane collection xa = [2,0,6,4] ya = [0,4,4,0] za = [-1,-2,-2,-1] #second collection xb = [2,0,0,2] yb = [0,4,4,0] zb = [-1,-2,2,1] #third collection xc = [2,0,6,4] yc = [0,4,4,0] zc = [1,2,2,1] #fourth collection xd = [4,6,6,4] yd = [0,4,4,0] zd = [1,2,-2,-1] #fifth collection (kept open, to watch the plot result) xe = [0,0,6,6] ye = [4,4,4,4] ze = [-2,2,2,-2] #sixth collection xf = [2,2,4,4] yf = [0,0,0,0] zf = [-1,1,1,-1] # to do verts = [zip(xa, ya,za),zip(xb, yb,zb),zip(xc, yc,zc),zip(xd, yd,zd),zip(xf, yf,zf)] ax.add_collection3d(Poly3DCollection(verts, facecolors=color, linewidths=1, alpha=0.5)) ax.add_collection3d(Line3DCollection(verts, colors='k', linewidths=0.2, linestyles=':')) # set axis view # add grid ax.grid(True) # view ax.set_xlim(-1,6) ax.set_ylim(-1,6) ax.set_zlim(-5,5) ax.view_init(elev=10., azim=110.) ax.get_xaxis().set_visible(True) ax.get_yaxis().set_visible(True) ax.set_autoscale_on(True) plt.show() Thanks for support. Regards, Claude Claude Falbriard Certified IT Specialist L2 - Middleware AMS Hortolândia / SP - Brazil phone: +55 13 9 9760 0453 cell: +55 13 9 8117 3316 e-mail: cl...@br... |