Hw can I find out vertices of all the polygons/cells in a voronoi diagram including unbounded cells?
5 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Voronoi Diagram 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!