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!