How to create an offset to the voronoi cells in Voronoi diagram?
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Naga
am 16 Sep. 2024
Bearbeitet: Naga
am 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:
0 Kommentare
Siehe auch
Kategorien
Mehr zu Voronoi Diagram finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!