How can I obtain the points between the vertices of a voronoi polygon?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Ronit
le 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!
0 commentaires
Voir également
Catégories
En savoir plus sur Voronoi Diagram dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!