How to match voronoi area to it's point

12 views (last 30 days)
Amit Ifrach
Amit Ifrach on 18 Aug 2021
Commented: Bjorn Gustavsson on 18 Aug 2021
I'm trying to find a command or a code that can match the voronoi areas I get out from voronoin command to the points they enclose. I use oast of KSSV's code, so if it seems fermiliar, it's from him.
that's the code:
[v,c] = voronoin([xroi yroi]) ;
vorareaacd45num10thin1st = zeros(length(c),1) ;
for i = 1:length(c)
v1 = v(c{i},1) ;
v2 = v(c{i},2) ;
vorarea(i) = polyarea(v1,v2) ;
Bjorn Gustavsson
Bjorn Gustavsson on 18 Aug 2021
The way I recall the Voronoi-boundaries are built from the line-segments prependicular to the midpoints of the Delaunay-triangulation-edges (normals halfway on the nearest-neighbour-lines, so the dual of the Delaunay-triangulation). If you could share a typical image it might be easier to modify your aproach?

Sign in to comment.

Answers (1)

Bjorn Gustavsson
Bjorn Gustavsson on 18 Aug 2021
The way I interpret your question each point [xroi,yroi] will be inside one Voronoi-cell (though my QD-tests leave a couple of edge-points outside the Voronoi-cells?). It should be possible to find out which by using inpolygon:
for i1 = length(c):-1:1
v1 = v(c{i1},1);
v2 = v(c{i1},2);
idx = find(inpolygon(xroi,yroi,v1,v2));
if ~isempty(idx)
idxXYinCellj(i1) = idx(1);
if numel(idx) > 1
disp(['Cell ',num2str(i1),' contains ',num2str(numel(idx)),' points?'])


Community Treasure Hunt

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

Start Hunting!