필터 지우기
필터 지우기

How to caluclate centroid of a voronoi cell of a voronoi diagram.

조회 수: 37 (최근 30일)
Pallov Anand
Pallov Anand 2023년 1월 3일
댓글: Pallov Anand 2023년 1월 4일
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
Bruno Luong
Bruno Luong 2023년 1월 3일
편집: Bruno Luong 2023년 1월 3일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Matt J
Matt J 2023년 1월 3일
편집: Matt J 2023년 1월 3일
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) )
centroids = 2×11
Inf 1.9180 1.1707 1.2800 1.1995 1.6029 Inf Inf Inf Inf Inf Inf 1.3544 1.4421 1.8802 0.5374 1.6873 Inf Inf Inf Inf Inf
  댓글 수: 4
Matt J
Matt J 2023년 1월 4일
Because you didn't download the files at the link I gave you.
Pallov Anand
Pallov Anand 2023년 1월 4일
Oh yes, my bad. I just downloaded voronoiPolyhedrons.m and was going through the overview given here
Now, I downloaded and its working now. Thanks a lot mate.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Constantino Carlos Reyes-Aldasoro
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
Pallov Anand
Pallov Anand 2023년 1월 3일
편집: Pallov Anand 2023년 1월 3일
Ya, right. Lets take one region with vertices:
(1.7038, 1.3731) ; (1.8661, 1.6435); (1.7780, 1.9520); (1.6864, 1.9864); (1.29, 1.59); (1.2929, 1.5786)
For this region, I think centroid can be calculated and it should lie inside the region.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Voronoi Diagram에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by