Monday, 15 March 2010

python - Return surface triangle of 3D scipy.spatial.Delaunay -



python - Return surface triangle of 3D scipy.spatial.Delaunay -

i have problem. seek triangulate points cloud scipy.spatial.delaunay. used:

tri = delaunay(points) # points: np.array() of 3d points indices = tri.simplices vertices = points[indices]

but, code homecoming tetrahedron. how possible homecoming triangle of surface only?

thanks

to work in code form, have parametrize surface 2d. illustration in case of ball (r,theta, psi), radius constant (drop out) , points given (theta,psi) 2d.

scipy delaunay n-dimensional triangulation, if give 3d points returns 3d objects. give 2d points , returns 2d objects.

below script used create polyhedra openscad. u , v parametrization (x , y) , these coordinates give delaunay. note "delaunay triangulation properties" apply in u,v coordinates (angles maximized in uv -space not xyz -space, etc).

the illustration modified re-create http://matplotlib.org/1.3.1/mpl_toolkits/mplot3d/tutorial.html uses triangulation function (maps delaunay eventually?)

import numpy np import matplotlib.pyplot plt mpl_toolkits.mplot3d import axes3d import matplotlib.tri mtri scipy.spatial import delaunay # u, v parameterisation variables u = np.array([0,0,0.5,1,1]) v = np.array([0,1,0.5,0,1]) x = u y = v z = np.array([0,0,1,0,0]) # triangulate parameter space determine triangles #tri = mtri.triangulation(u, v) tri = delaunay(np.array([u,v]).t) print 'polyhedron(faces = [' #for vert in tri.triangles: vert in tri.simplices: print '[%d,%d,%d],' % (vert[0],vert[1],vert[2]), print '], points = [' in range(x.shape[0]): print '[%f,%f,%f],' % (x[i], y[i], z[i]), print ']);' fig = plt.figure() ax = fig.add_subplot(1, 1, 1, projection='3d') # triangles in parameter space determine x, y, z points # connected border #ax.plot_trisurf(x, y, z, triangles=tri.triangles, cmap=plt.cm.spectral) ax.plot_trisurf(x, y, z, triangles=tri.simplices, cmap=plt.cm.spectral) plt.show()

below (slightly more structured) text output:

polyhedron( faces = [[2,1,0], [3,2,0], [4,2,3], [2,4,1], ], points = [[0.000000,0.000000,0.000000], [0.000000,1.000000,0.000000], [0.500000,0.500000,1.000000], [1.000000,0.000000,0.000000], [1.000000,1.000000,0.000000], ]);

python scipy cloud points delaunay

No comments:

Post a Comment