How to create an offset to the voronoi cells in Voronoi diagram?

1 vue (au cours des 30 derniers jours)
ruban ramalingam
ruban ramalingam le 11 Mar 2019
Modifié(e) : Naga le 16 Sep 2024
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.

Réponses (1)

Naga
Naga le 16 Sep 2024
Modifié(e) : Naga le 16 Sep 2024
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:

Catégories

En savoir plus sur Voronoi Diagram dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by