Speed up for loop in voronoi?

1 visualización (últimos 30 días)
giometar
giometar el 14 de Feb. de 2020
Editada: Geoff Hayes el 14 de Feb. de 2020
Hello
I need to calculate area of Voronoi polygons for around 3000 points. I use VoronoiLimit function to bound it (specific reason) and then use for loop to perform calculations. But it is high time consuming. Can someone help me to speed up the code?
I try to use InPolygon mex function but there is no significant improvements...
Tahnks
% Generate random points
x=(rand(1,3000)*10000);
y=(rand(1,3000)*10000);
x=x';
y=y';
% Create traingle boundary for VoronoiLimit function
T_bound=[37093 -15136;5000 30629 ;-27093 -15136];
% Compute bounded voronoi:
% https://www.mathworks.com/matlabcentral/fileexchange/34428-voronoilimit-varargin
[vvor,cvor]=VoronoiLimit(x,y,'bs_ext',T_bound,'figure','off');
% Compute areas off Voronoi polygons and place it on the exact place
A = zeros(length(cvor),1) ;
for i = 1:length(cvor)
for j=1:length(cvor)
v1 = vvor(cvor{i},1) ;
v2 = vvor(cvor{i},2) ;
test=inpolygon(x(j),y(j),v1,v2); % testing if points is inside polygon
if test==1
A(j) = polyarea(v1,v2);
end
end
end

Respuestas (0)

Categorías

Más información sobre Voronoi Diagram en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by