title: Delaunay Triangulation of points from 2D surface in 3D with python?
body: <p>I have a collection of 3D points. These points are sampled at constant levels (z=0,1,...,7). An image should make it clear:</p>
  
  <p><img src="https://i.stack.imgur.com/b54lu.png" alt="point collection"></p>
  
  <p>These points are in a numpy ndarray of shape <code>(N, 3)</code> called <code>X</code>. The above plot is created using:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  from mpl_toolkits.mplot3d import Axes3D
  
  X = load('points.npy')
  fig = plt.figure()
  ax = fig.gca(projection='3d')
  ax.plot_wireframe(X[:,0], X[:,1], X[:,2])
  ax.scatter(X[:,0], X[:,1], X[:,2])
  plt.draw()
  </code></pre>
  
  <p>I'd like to instead triangulate only the surface of this object, and plot the surface. I do not want the convex hull of this object, however, because this loses subtle shape information I'd like to be able to inspect.</p>
  
  <p>I have tried <code>ax.plot_trisurf(X[:,0], X[:,1], X[:,2])</code>, but this results in the following mess:</p>
  
  <p><img src="https://i.stack.imgur.com/bIDUF.png" alt="mess"></p>
  
  <p>Any help?</p>
  
  <h2>Example data</h2>
  
  <p>Here's a snippet to generate 3D data that is representative of the problem:</p>
  
  <pre><code>import numpy as np
  X = []
  for i in range(8):
      t = np.linspace(0,2*np.pi,np.random.randint(30,50))
      for j in range(t.shape[0]):
          # random circular objects...
          X.append([
              (-0.05*(i-3.5)**2+1)*np.cos(t[j])+0.1*np.random.rand()-0.05,
              (-0.05*(i-3.5)**2+1)*np.sin(t[j])+0.1*np.random.rand()-0.05,
              i
          ])
  X = np.array(X)
  </code></pre>
  
  <h2>Example data from original image</h2>
  
  <p>Here's a pastebin to the original data:</p>
  
  <p><a href="http://pastebin.com/YBZhJcsV" rel="noreferrer">http://pastebin.com/YBZhJcsV</a></p>
  
  <p>Here are the slices along constant z:</p>
  
  <p><img src="https://i.stack.imgur.com/Tl8kW.png" alt="enter no image description here"></p>