2

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.

Eman
  • 23
  • 4
  • I saw this answer. But, it does not related to what I want to get. It is used to draw lines connecting any points. I didn't want to do that. I want to get the vertices and edges of each polygon, not to draw lines between any points. – Eman Sep 08 '18 at 06:20
  • 1
    The [documentation to `voronoi`](https://www.mathworks.com/help/matlab/ref/voronoi.html) says “For the topology of the Voronoi diagram, i.e., the vertices for each Voronoi cell, use [`voronoin`](https://www.mathworks.com/help/matlab/ref/voronoin.html).” – Cris Luengo Sep 08 '18 at 14:31
  • Thanks for your help. I will try it. – Eman Sep 08 '18 at 14:51

1 Answers1

0

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.

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
  • @ Cris Luengo Thanks for your help. It works successfully. But, when I used it in a for loop as following; `[V,C] = voronoin(X); for ii=1:length(C) disp(V(C{ii},:)); end` It gave the vertices of **last polygon** _X10_ **only**. So, If I want to get vertices; e.g. for first polygon X1, I should do it manually, like that **V(C{1},:)**. So, how to store **V(C{ii},:)** to get the output like a large matrix that consists of 10 sub matrices; each sub-matrix contain the vertices of each polygon. – Eman Sep 08 '18 at 15:19
  • @Eman: that loop should print all vertices for all cells. I’m not sure why you see only the last one. Note that `disp` might make it look like all matrices shown are one big matrix rather than 10 small ones. You could remove `disp` form there for a clearer output: `for ii=1:numel(C), V(C{ii},:), end` – Cris Luengo Sep 08 '18 at 15:28
  • Thanks so much, it worked. – Eman Sep 08 '18 at 15:54