How to create an offset to the voronoi cells in Voronoi diagram?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Naga
el 16 de Sept. de 2024
Editada: Naga
el 16 de Sept. de 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 comentarios
Ver también
Categorías
Más información sobre Voronoi Diagram en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!