How can I obtain the points between the vertices of a voronoi polygon?

4 次查看(过去 30 天)
Hi,
I am using the the voronoi code:
[vx,vy] = voronoi(x,y)
where x and y are the coordinates of some random points, vx and vy the coordinates of the vertices of the polygons.
The problem is that I need to know not only these vertices, but also some points (say 3) between these.
Is there a way to obtain points between these vertices?
Thank you for the help

回答(1 个)

Ronit
Ronit 2024-9-17
Hello Matteo,
To obtain additional points between the vertices of the Voronoi diagram, you can interpolate between the vertices. To interpolate points between Voronoi vertices, you can use the "linspace" function to generate evenly spaced points between each pair of vertices. Please refer to the following approach:
x = rand(1, 10);
y = rand(1, 10);
[vx, vy] = voronoi(x, y);
% Number of points to interpolate between each pair
numPoints = 3;
% Initialize arrays to hold interpolated points
interpVx = [];
interpVy = [];
% Loop through each pair of Voronoi vertices
for i = 1:length(vx)-1
% Get the current pair of vertices
x1 = vx(i);
y1 = vy(i);
x2 = vx(i+1);
y2 = vy(i+1);
% Interpolate points between the current pair of vertices
interpX = linspace(x1, x2, numPoints+2); % +2 to include the endpoints
interpY = linspace(y1, y2, numPoints+2);
% Exclude the first and last points (original vertices)
interpVx = [interpVx, interpX(2:end-1)];
interpVy = [interpVy, interpY(2:end-1)];
end
figure;
plot(x, y, 'r+', vx, vy, 'b-');
hold on;
plot(interpVx, interpVy, 'go');
title('Voronoi Diagram with Interpolated Points');
xlabel('x');
ylabel('y');
legend('Original Points', 'Voronoi Edges', 'Interpolated Points');
hold off;
Please refer to the documentation link of "linspace" function:
I hope this helps with your query!

类别

Help CenterFile Exchange 中查找有关 Voronoi Diagram 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by