Search code examples
matlabgeometrycomputational-geometryvoronoi

How to get the vertices and edges of each polygon of the voronoi diagram using matlab?


I have the following code to draw the voronoi diagram;

 X = [ 0.018504 0.5187; 0.23114 0.70406;...
      0.4447 0.37589;0.45647  0.83682;...
      0.48598 0.59816; 0.60684 0.95388;...
      0.7621 0.44282; 0.82141 0.02221;...
      0.8913 0.84074; 0.95013  0.95278];

[VX,VY] = voronoi(X(:,1),X(:,2));

 Assign_labels_to_all_points ( X ,X(:,1),X(:,2));

plot(VX,VY,'-k','linewidth',2); 
xlim([-0.2,1.2]);
ylim([-0.2,1.2]);

It is shown in the Voronoi Diagram below:
Voronoi Diagram image

So, my question is: How to get the vertices and edges of each polygon of the voronoi diagram?

For example;

Polygon X1 has 4 edges and 4 vertices points. I want to get the values of these vertices points. So, for each polygon of the 10 polygons; I want to get its vertices values and number of its edges.


Solution

  • Given a matrix with coordinates X,

    [V,C] = voronoin(X);
    

    returns an array V with vertices and a cell array C with a matrix for each cell of the diagram. The set of points

    V(C{ii},:)
    

    contains the vertices to cell number ii, corresponding to centroid X(ii,:).

    See the documentation to voronoin.