% Script C7_test
% Checks out the class ConvexPoly
clear
rand('seed',0)
close all
% Parameters to play with...
s = 6; % Polygons will be randomly placed inside
% the square fill([-s s s -s],[-s -s s s],'y')
n = 7; % The number of sides in each polygon
N = 12; % The number of polygons randomly placed in the square
% N = 120 % This is used to check efficiency
% Generate and display all the polygons...
figure
fill([-s s s -s],[-s -s s s],'y')
axis square
hold on
for k=1:N
P(k) = ConvexPoly(n);
% Random translation...
delX = (s-1)*(-1+2*rand());
delY = (s-1)*(-1+2*rand());
P(k).Translate(delX,delY);
P(k).Show('r')
end
% Tabulate all the overlapping pairs...
tic
Count = zeros(N,N);
for i=1:N
for j=i+1:N
if P(i).Disjoint(P(j))
% The i-th and j-th polygons overlap...
Count(i,j) = 1;
Count(j,i) = 1;
end
end
end
time = toc
% Count all the off-diagonal 0's and halve...
nOverlaps = (sum(sum(Count==0))-N)/2;
% A column with N-1 1's signals a polygon that is disjoint from all the
% others...
nDisjoint = sum(sum(Count)==N-1);
title(sprintf('#Disjoint = %1d #Overlapping Pairs = %1d',nDisjoint,nOverlaps),...
'fontsize',16)