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

4 visualizzazioni (ultimi 30 giorni)
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

Risposte (1)

Ronit
Ronit il 17 Set 2024
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!

Categorie

Scopri di più su Voronoi Diagram in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by