Speed up for loop in voronoi?
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Voronoi Diagram 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!