0

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.

How I expected the graph to look like: How I expected the graph to look like.

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:

The voronoi polyhedrons that are formed out of my data points.

The coordinates of my data set are :

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];

I used the code in the link (http://www.mathworks.com/help/matlab/math/voronoi-diagrams.html) for drawing voronoi on these points and I get an error like this:

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);

Basically, the vector V which hold the vertices of polygons has Inf values in the first row. Even if I forcefully remove the first row, I dont get my required results. The code is shown below:

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')

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:

 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
Will
  • 1,835
  • 10
  • 21
Swathi
  • 3
  • 3

2 Answers2

0

I'm not sure what happened, but the first row of V contains only Inf values, this is what causes the errors further on.

dt = delaunayTriangulation(X);
figure
[V,R] = voronoiDiagram(dt);
V(1,:) = []; %// INTERESTING LINE, removes the Inf values
tid = nearestNeighbor(dt,0,0,0);
XR10 = V(R{tid},:);
K = convhull(XR10);
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')

I get the following plot:

enter image description here

Adriaan
  • 17,741
  • 7
  • 42
  • 75
  • I tried something like what you suggested. If you plot the points using plot3(X(:,1),X(:,2),X(:,3), '*'); and execute the code however, all the points are not engulfed by these polyhedrons. Also, if you look closely, it doesn't seem like the voronoi polyhedrons are formed around each of these points. I'd also like to point out that, changing the nearest neighbor points to the center most point which is (116,166,15) gives a bit more coverage than (0,0,0). However, this still doesn't solve my issue. – Swathi Oct 17 '15 at 15:46
0

From the referenced documentation page:

Observe that the Voronoi regions associated with points on the convex hull are unbounded.

That is why the points you see are not enclosed by polyhedrons – there is no finite polyhedron defined by any of their Voronoi regions.

The attached image of what you expected to see looks like it shows the intersection of the Voronoi regions with the minimum bounding cube of the finite vertices in the Voronoi diagram. This is not trivial to calculate with built in MATLAB functions since none of them offer a definition of the direction of the semi-infinite elements in the Voronoi diagram. The polyhedrons defined by the intersection of the Voronoi diagram and a cube may contain vertices that consist of:

  • The finite vertices in the corresponding Voronoi region
  • Points of intersection between semi-infinite faces in the Voronoi region and edges in the cube
  • Points of intersection between semi-infinite edges in the Voronoi region and faces in the cube
  • Vertices of the cube enclosed by the boundary connecting the above intersection points

This is a challenging geometrical problem I won't attempt to solve. You can see the triangulation-based method MATLAB uses to calculate the direction of 2D lines-to-infinity using edit voronoi – this may offer clues as to how to generate the same in 3D.

Will
  • 1,835
  • 10
  • 21