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:
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 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