Try this:

numCircles = 10;

xy = rand(numCircles, 2);

radii = 0.1 * rand(numCircles, 1) + 0.1;

viscircles(xy, radii);

for k = 1 : numCircles

text(xy(k, 1), xy(k, 2), num2str(k));

end

axis square;

for k = 1 : numCircles

distances = sqrt((xy(k, 1) - xy(:, 1)).^2 + (xy(k, 2) - xy(:, 2)) .^2);

sumOfRadii = radii(k) + radii(:);

intersectingIndexes = distances < sumOfRadii;

intersectingIndexes(k) = false;

intersectingIndexes = find(intersectingIndexes);

for k2 = 1 : length(intersectingIndexes)

fprintf('Circle %d intersects with circle #%d.\n', k, intersectingIndexes(k2));

end

end

You see

Circle 1 intersects with circle #2.

Circle 1 intersects with circle #5.

Circle 1 intersects with circle #7.

Circle 2 intersects with circle #1.

Circle 2 intersects with circle #5.

Circle 3 intersects with circle #7.

Circle 3 intersects with circle #9.

Circle 5 intersects with circle #1.

Circle 5 intersects with circle #2.

Circle 6 intersects with circle #10.

Circle 7 intersects with circle #1.

Circle 7 intersects with circle #3.

Circle 8 intersects with circle #9.

Circle 9 intersects with circle #3.

Circle 9 intersects with circle #8.

Circle 10 intersects with circle #6.

and it's trivial to find out if one circle is completely contained within another. See if you can do it.

## Best Answer