title: Drawing 3D voronoi polyhedrons over human body points in MATLAB
body: <p>I am trying to draw voronoi polyhedrons in 3D around a set of points (which are coordinates of the position of sensors) placed on a human frame. I found a couple of ways to do it in MATLAB. Except that none of them are giving me the right kind of polyhedrons. I understand voronoi in 3D for a set of points should appear like this.</p>
  
  <p>How I expected the graph to look like:
  <img src="https://i.stack.imgur.com/O3pws.jpg" alt="How I expected the graph to look like."> </p>
  
  <p>For my set of data points, the voronoi polyhedrons do not encapsulate all of the points. The voronoi polyhedrons that are formed out of my data points look something like this:</p>
  
  <p><img src="https://i.stack.imgur.com/borDs.jpg" alt="The voronoi polyhedrons that are formed out of my data points">.</p>
  
  <p>The coordinates of my data set are : </p>
  
  <pre><code>X= [116,191,0;
      108,183,0;
      120,175,0;
      100,162,12;
      116,166,8;
      133,158,14;
      100,150,0;
      116,166,15;
      125,144,8;
      90,133,5;
      108,133,2.5;
      144,133,5;
      116,116,15;
      144,116,6.5;
      108,100,-5;
      150,100,15;
      83,100,15;
      108,83,14;
      100,58,13;
      133,50,13;
      100,25,11;
      133,30,12;
      100,8.3,14;
      133,8.3,14];
  </code></pre>
  
  <p>I used the code in the link (<a href="http://www.mathworks.com/help/matlab/math/voronoi-diagrams.html" rel="nofollow noreferrer">http://www.mathworks.com/help/matlab/math/voronoi-diagrams.html</a>) for drawing voronoi on these points and I get an error like this:</p>
  
  <pre><code>Error using convhull
  The coordinates of the input points must be finite values; Inf and NaN are not permitted.
  
  Error in best3D_original (line 38)
  K = convhull(XR10);
  </code></pre>
  
  <p>Basically, the vector V which hold the vertices of polygons has <code>Inf</code> values in the first row. Even if I forcefully remove the first row, I dont get my required results. The code is shown below:</p>
  
  <pre><code>dt = delaunayTriangulation(X);
  figure
  [V,R] = voronoiDiagram(dt);
  tid = nearestNeighbor(dt,0,0,0);
  XR10 = V(R{tid},:);
  K = convhull(XR10);
  K
  defaultFaceColor  = [0.6875 0.8750 0.8984];
  trisurf(K, XR10(:,1) ,XR10(:,2) ,XR10(:,3) , ...
          'FaceColor', defaultFaceColor, 'FaceAlpha',0.9)
  title('3-D Voronoi Region')
  </code></pre>
  
  <p>I have also tried incorporating a patch function separately in another script for the same set of data points. The code looks something like this:</p>
  
  <pre><code> X=[x y z]; 
   [V,C]=voronoin(X); 
   for k=1:length(C) 
       disp(C{k}) 
   end 
   for k=2:length(C) 
       if all(C{k}~=1) 
          VertCell = V(C{k},:); 
                   KVert = convhulln(VertCell); 
                   patch('Vertices',VertCell,'Faces',KVert,'FaceColor','g','FaceAlpha',0.5); 
      end 
   end
  </code></pre>