Questions about the Detailed Settings of Voronoi Diagrams ボロノイ図の細かな設定について質問です
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have been reading an example from a book and am trying to recreate the diagram using Voronoi diagrams. However, I want to consider a bounded region [0,1], [1,0], but when using the voronoi function, the lines extend beyond the boundaries. I would like to obtain information such as the area and centroid of the bounded regions, so I want to create the Voronoi diagram with these bounded constraints in mind. Is this possible?
ある書籍の例を読み、ボロノイ図を用いてその図を再現したいと考えています。
しかし有界の領域[0,1],[1,0]について考えたいところ、voronoiでは枠外を超えて線が伸びてしまいます。
有界領域の面積や重心などの情報を得たいため、ボロノイ図を有界の制約を踏まえて作成したいのですが可能でしょうか?
clear
close all
figure()
x = [0.2 0.6 0.9 0.7 0.8 0.5 0.4 0.1 0.3 0.5];
y = [0.7 0.9 0.8 0.6 0.3 0.4 0.2 0.1 0.3 0.5];
X = [x',y'];
vrn_obj = voronoi(X(:,1),X(:,2));
[vx,vy] = voronoi(X(:,1),X(:,2));
edge_set =[vx',vy'];
nump = size(X,1);
plabels = arrayfun(@(n) {sprintf('X%d', n)}, (1:nump)');
hold on
Hpl = text(X(:,1), X(:,2), plabels, 'FontWeight', ...
'bold', 'HorizontalAlignment','center', ...
'BackgroundColor', 'none');
dt = delaunayTriangulation(X);
hold on
triplot(dt,'--');
hold off
axis equal
% xlim([0 1])
% ylim([0 1])
grid on
1 comentario
Respuestas (1)
Ronit
el 16 de Sept. de 2024
Hello Irosy,
To create a Voronoi diagram with bounded constraints (within the region [0,1] x [0,1]), you can clip the Voronoi cells at the boundaries. This can be achieved by using a combination of functions from MATLAB's Computational Geometry Toolbox. The following steps can be used:
- Delaunay Triangulation: The delaunayTriangulation function is used to create a triangulation from the set of points X.
- Voronoi Diagram: The voronoiDiagram function generates the Voronoi vertices v and cells c.
- Bounding Box: A polyshape object is created to represent the bounding box, which is used to clip the Voronoi cells.
- Intersection: The intersect function is used to clip each Voronoi cell with the bounding box, resulting in a bounded cell.
- Area Calculation: The area method of the polyshape object calculates the area of the bounded Voronoi cell.
- Centroid Calculation: The centroid method provides the x and y coordinates of the centroid of the bounded Voronoi cell.
- Plotting: Each bounded Voronoi cell and its centroid are plotted, with the centroid marked by a red cross.
clear
close all
figure()
x = [0.2 0.6 0.9 0.7 0.8 0.5 0.4 0.1 0.3 0.5];
y = [0.7 0.9 0.8 0.6 0.3 0.4 0.2 0.1 0.3 0.5];
X = [x', y'];
dt = delaunayTriangulation(X);
[v, c] = voronoiDiagram(dt);
% Define the bounding box as a polyshape
boundingBox = polyshape([0 1 1 0], [0 0 1 1]);
% Plot the Voronoi diagram with bounded constraints
hold on
for i = 1:length(c)
if all(c{i} ~= 1)
% Get the coordinates of the Voronoi cell
poly = v(c{i}, :);
voronoiCell = polyshape(poly);
boundedCell = intersect(voronoiCell, boundingBox);
plot(boundedCell, 'FaceColor', rand(1,3), 'FaceAlpha', 0.5, 'EdgeColor', 'k');
% Calculate the area of the bounded Voronoi cell
A = area(boundedCell);
disp(['Area of cell ', num2str(i), ': ', num2str(A)]);
% Calculate the centroid of the bounded Voronoi cell
[cx, cy] = centroid(boundedCell);
disp(['Centroid of cell ', num2str(i), ': (', num2str(cx), ', ', num2str(cy), ')']);
% Plot the centroid
plot(cx, cy, 'rx', 'MarkerSize', 8, 'LineWidth', 2);
end
end
% Plot the points
plot(X(:,1), X(:,2), 'MarkerFaceColor', 'k');
nump = size(X, 1);
plabels = arrayfun(@(n) {sprintf('X%d', n)}, (1:nump)');
Hpl = text(X(:,1), X(:,2), plabels, 'FontWeight', ...
'bold', 'HorizontalAlignment', 'center', ...
'BackgroundColor', 'none');
xlim([0 1])
ylim([0 1])
axis equal
grid on
hold off
Please go through the following MATLAB documentations for better understanding.
- voronoiDiagram - https://www.mathworks.com/help/matlab/ref/delaunaytriangulation.voronoidiagram.html?s_tid=doc_ta
- polyshape - https://www.mathworks.com/help/matlab/ref/polyshape.html
- intersect - https://www.mathworks.com/help/matlab/ref/double.intersect.html
- area – https://www.mathworks.com/help/matlab/ref/area.html#d126e50129
- centroid - https://www.mathworks.com/help/matlab/ref/polyshape.centroid.html
I hope it helps with your query!
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!