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

4 Ansichten (letzte 30 Tage)
Matteo Cantoresi
Matteo Cantoresi am 26 Jun. 2020
Beantwortet: Ronit am 17 Sep. 2024
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

Antworten (1)

Ronit
Ronit am 17 Sep. 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!

Kategorien

Mehr zu Voronoi Diagram finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by