“…% finds overlap of all quadrilaterals from series1 with all quadrilaterals from series2 beta1=zeros(m,1); %Series 1; default zeros is no overlap beta2=zeros(m,1); %Series 2; default zeros is no overlap (beta1 and beta2 will be same if no timelag) Q=NaN (2,16); R=NaN (2,16);S=NaN (2,16);T=NaN (2,16);%16 to compare 4 vectors of quad1 to 2 for t=1:m % STAGE4a: create combinations of the 16 vectors; series1 vectors Q(1,:)=[repmat(Px1(1,t),1,4),repmat(Px1(2,t),1,4),repmat(Px1(3,t),1,4),repmat(Px1(4,t),1 ,4)]; Q(2,:)=[repmat(Py1(1,t),1,4),repmat(Py1(2,t),1,4),repmat(Py1(3,t),1,4),repmat(Py1(4,t),1 ,4)]; R(1,:)=[repmat(Px1(2,t),1,4),repmat(Px1(3,t),1,4),repmat(Px1(4,t),1,4),repmat(Px1(1,t),1 ,4)]; R(2,:)=[repmat(Py1(2,t),1,4),repmat(Py1(3,t),1,4),repmat(Py1(4,t),1,4),repmat(Py1 (1,t) if W<=0 %skips this section if already know there is an overlap % find which quadrilaterals has lowest y value, and subtract min y from all y's % order so only need check 2 is inside 1 (and no need to check reverse that 1 inside 2) Z=[Px1 ; else W=1; %i.e. no cross, so quad2ofZ within quad1ofZ, so quads overlap end end end beta1(t)=beta1(t)+W; % STAGE4c beta2(h)=beta2(h)+W; end end gamma=isfinite(1./(beta1+beta2)); % STAGE4d…”