Hw can I find out vertices of all the polygons/cells in a voronoi diagram including unbounded cells?

5 ビュー (過去 30 日間)
Nidhi
Nidhi 2013 年 2 月 18 日
回答済み: Naga 2024 年 9 月 17 日
How can I find out vertices of all the polygons/cells in a voronoi diagram including unbounded cells? [V,C] =voronoin() functions gives vertices of only bounded cells but I need vertices of all the cells whether it is bounded or unbounded. How do I get it?

回答 (1 件)

Naga
Naga 2024 年 9 月 17 日
Hello Nidhi,
I understand you need the vertices of all the polygons in a voronoi diagram. The 'voronoin' function provides the vertices of the Voronoi diagram and the indices of these vertices for each cell. While it might seem like it only gives you bounded cells, it actually provides the vertices for all cells, including unbounded ones.
The key is in how you interpret the output. 'V' is a matrix where each row represents a vertex in the Voronoi diagram. 'C' is a cell array where each cell contains a vector of indices into V, representing the vertices of the corresponding Voronoi cell. Unbounded cells will have vertices that include Inf in their coordinates. These are represented as indices in 'C' that point to the first row of 'V', which usually contains Inf values.
Here's how you can extract the vertices for all Voronoi cells, including unbounded ones:
% Sample points
points = rand(10, 2);
% Compute the Voronoi diagram
[V, C] = voronoin(points);
% Plot the Voronoi diagram
figure; hold on;
plot(points(:,1), points(:,2), 'ro'); % Plot the points
% Iterate over each cell
for i = 1:length(C)
% Extract the vertices for the i-th Voronoi cell
cellVertices = V(C{i}, :);
% Plot bounded cells
if all(~isinf(cellVertices), 'all')
fill(cellVertices(:,1), cellVertices(:,2), 'cyan', 'FaceAlpha', 0.3);
else
% Plot lines for unbounded cells
finiteVertices = cellVertices(~isinf(cellVertices(:,1)), :);
plot(finiteVertices(:,1), finiteVertices(:,2), 'b-');
end
end
title('Voronoi Diagram with Bounded and Unbounded Cells');
axis equal; hold off;
This approach allows you to handle and visualize both bounded and unbounded Voronoi cells effectively

カテゴリ

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