Find polygon in voronoi diagram

3 ビュー (過去 30 日間)
Jonathan Mayers
Jonathan Mayers 2016 年 7 月 20 日
コメント済み: HG 2021 年 6 月 14 日
Hi all,
If I generate a Voronoi diagram via the below code, how would I find the points that form a polygon from the diagram?
lambda = 10;
npoints = poissrnd(lambda);
pproc = rand(npoints,2);
x = pproc(:,1);
y = pproc(:,2);
[vx,vy] = voronoi(x,y);
plot(vx,vy);
vx and vy are 2-by-N matrices where N varies;

採用された回答

Jonathan Mayers
Jonathan Mayers 2016 年 7 月 20 日
Hi all,
The following code solves the problem.
clc; close all; clearvars;
lambda = 10;
npoints = poissrnd(lambda);
pproc = rand(npoints,2);
x = pproc(:,1);
y = pproc(:,2);
[vx,vy] = voronoi(x,y);
plot(vx,vy,'k-'); hold on; axis([0 2 0 2]);
% Perform DT on original x and y
DT = delaunayTriangulation(x,y);
% V contains vertices
% R contains regions
[V,R] = voronoiDiagram(DT);
% Obtain vertices enclosing region 1
coord = V(R{1},:);
% for while loop
i = 2;
% Exclude infinite vertices
% Loop until no region has infinite vertices
while ismember(Inf,coord)
coord = V(R{i},:);
i = i + 1;
end
% Append the first vertex just to plot a complete polygon
coord = [coord;coord(1,:)];
% Plot the polygon
plot(coord(:,1),coord(:,2),'b-','linewidth',2);
The following image is an example output of the above code.
  2 件のコメント
Karishma q
Karishma q 2019 年 5 月 8 日
How do I get the co-ordinates of each polygon separately? I tried adding a for loop which defines the number of regions, but I am still getting the vertices of region1. Also [vx, vy]=voronoi(x,y) provides all the coordinates, I want for the individual regions. Can you help me on this?
HG
HG 2021 年 6 月 14 日

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeVoronoi Diagram についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by