Speed up for loop in voronoi?

3 ビュー (過去 30 日間)
giometar
giometar 2020 年 2 月 14 日
編集済み: Geoff Hayes 2020 年 2 月 14 日
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 件)

カテゴリ

Help Center および File ExchangeVoronoi Diagram についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by