Speed up for loop in voronoi?

조회 수: 1 (최근 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 CenterFile Exchange에서 Voronoi Diagram에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by