How to create an offset to the voronoi cells in Voronoi diagram?
4 ビュー (過去 30 日間)
古いコメントを表示
A voronoi diagram has been constructed using the following codes from the mathworks documentation:
x = gallery('uniformdata',[1 10],0);
y = gallery('uniformdata',[1 10],1);
voronoi(x,y)
In this voronoi diagram, how to create an offset to the voronoi cells like the attached image file?
Please find the attachment.
0 件のコメント
回答 (1 件)
Naga
2024 年 9 月 16 日
編集済み: Naga
2024 年 9 月 16 日
Hello Ruban,
To create an offset to the Voronoi cells like in the attached image, you can use the 'polybuffer' function in MATLAB to create a buffer around each Voronoi cell. Here’s an example of how you can achieve this:
% Generate random points
x = gallery('uniformdata',[1 10],0);
y = gallery('uniformdata',[1 10],1);
% Create Voronoi diagram
[vx, vy] = voronoi(x, y);
plot(vx, vy, '-r', x, y, '.k');
hold on;
% Compute Voronoi vertices and cells
dt = delaunayTriangulation(x', y');
[V, C] = voronoiDiagram(dt);
% Plot original Voronoi cells
for i = 1:length(C)
if all(C{i}~=1) % Skip the first vertex which is at infinity
fill(V(C{i},1), V(C{i},2), 'r', 'FaceAlpha', 0.3);
end
end
% Create offset Voronoi cells
offset = 0.05; % Adjust this value for the desired offset
for i = 1:length(C)
if all(C{i}~=1) % Skip the first vertex which is at infinity
poly = polyshape(V(C{i},1), V(C{i},2));
offsetPoly = polybuffer(poly, -offset);
plot(offsetPoly, 'EdgeColor', 'b', 'FaceAlpha', 0.3);
end
end
hold off;
This code will create an offset around each Voronoi cell, similar to the blue lines in your attached image. Adjust the offset value to control the distance of the offset.
Refere to the below documentation link for more information on 'polybffer' function:
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!