After you generate the circle centers and their radii, you can run the following code to find the indices of the iterations that create less than 5 intersections.
M = zeros(n);
for i=1:n-1
for j=i+1:n
if norm([x_pos(i)-x_pos(j),y_pos(i)-y_pos(j)])<rad(i)+rad(j) && norm([x_pos(i)-x_pos(j),y_pos(i)-y_pos(j)])>abs(rad(i)-rad(j))
M(i,j)=1;
M(j,i)=1;
end
end
end
index = zeros(n,1);
for i = 1:n
ind = find(M(:,i)~=0);
if ~isempty(ind)
if length(ind)>=5
continue;
else
M1 = M(ind,ind);
if length(ind)+1/2*sum(sum(M1))>=5
continue;
else
index(i)=1;
end
end
end
end
idx = find(index~=0);
The indices of the iterations which create less than 5 intersections are stored in the variable idx. Iterate on idx, and you can discard iterations that create 5 or more than 5 intersections.
Best Answer