Speed up for loop in voronoi?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Voronoi Diagram finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!