How to caluclate centroid of a voronoi cell of a voronoi diagram.
28 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pallov Anand
el 3 de En. de 2023
Comentada: Pallov Anand
el 4 de En. de 2023
Suppose I have generated a voronoi diagram by following code:
X=[1 2 1.1 1.3 1.4 1.5 1.3 1.2 1.8 2.1 2.2];
Y=[1.5 1.3 1.5 1.8 1.4 1.6 2.5 2.3 2.4 1.1 1.8];
voronoi(X,Y)
Now, once the voronoi diagram is generated, how to find the centroid of each voronoi cell. I know there are lot of algorithms. One of them is Lloyd's Algorithm, the code of which is given here
but after running the script , I am getting this error:
'poly2cw' requires Mapping Toolbox.
Error in lloydsAlgorithm>VoronoiBounded (line 178)
[X2, Y2] = poly2cw(V(C{ij},1),V(C{ij},2));
Error in lloydsAlgorithm (line 89)
[v,c]=VoronoiBounded(Px,Py, crs);
Can anyone help me in this.
1 comentario
Bruno Luong
el 3 de En. de 2023
Editada: Bruno Luong
el 3 de En. de 2023
The Vorinoi cells that contain a seed on the hull are unbounded, there is no centroid for such cells.
MATLAB voronoi just cuts them with an empiric bounding box. So of you use those outer vertexes the result is randomly cut.
Respuesta aceptada
Matt J
el 3 de En. de 2023
Editada: Matt J
el 3 de En. de 2023
The voronoi cells are always convex, so assuming it is bounded, you can just take the mean of all the vertices of each cell.
X=[1 2 1.1 1.3 1.4 1.5 1.3 1.2 1.8 2.1 2.2];
Y=[1.5 1.3 1.5 1.8 1.4 1.6 2.5 2.3 2.4 1.1 1.8];
[V,C]=voronoin([X;Y]');
centroids = cell2mat( cellfun(@(c) mean(V(c,:),1)' , C','uni', 0) )
4 comentarios
Más respuestas (1)
Constantino Carlos Reyes-Aldasoro
el 3 de En. de 2023
This is not a trivial problem especially because the voronoi algorithm does not give you a series of closed polygons, i.e. change the axis of your current problem
X=[1 2 1.1 1.3 1.4 1.5 1.3 1.2 1.8 2.1 2.2];
Y=[1.5 1.3 1.5 1.8 1.4 1.6 2.5 2.3 2.4 1.1 1.8];
voronoi(X,Y)
axis([-2 4 -3 4])
You will see that the voronoi is finding lines that divide the points that you have provided, but it is not essentially generating polygons. Only some of these would be closed and then a centroid makes sense, but not for all of them
1 comentario
Ver también
Categorías
Más información sobre Voronoi Diagram en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!