MATLAB: Find number of circles that intersect certain boundary

circle intersecting shape coordinates

So my script produces two centre circles and then generates other circles of a distributed radius and location. How do I go about finding the radius of the circles that intersect the outer circle but not the inner circle?
% code
th = linspace(0,2*pi);
r = 3;
x = r*cos(th);
y = r*sin(th);
C = zeros(1:2);
xc1 = C(1,1)+x ;
yc1 = C(1,2)+y ;
hold on
t = plot(xc1,yc1) % Plot tunnel of 3m radius
r = 5;
x = r*cos(th);
y = r*sin(th);
C = zeros(1:2);
xc2 = C(1,1)+x ;
yc2 = C(1,2)+y ;
hold on
t2 = plot(xc2,yc2); % Plot tunnel of 3m radius with 2m exclusion
% Produce random circles
for i = (1:10000) % Iterate as many times as needed
R = 0.01 + (1.2 - 0.01)*sum(rand(10000,6),2)/6; % truncated normal distribution from 0.01 to 1.2
r = datasample(R,1);
s(i) = (r^2)*pi;
s = sum(s);
if s < ((50^2)*0.1) % Plot circles until they fill up x% of 50x50 axes
th1 = linspace(0,2*pi);
x1 = r*cos(th1);
y1 = r*sin(th1);
C1 = (-25 + (25+25).*rand(1:2)); % Random centre between -25 and 25
xc = C1(1,1)+x1 ;
yc = C1(1,2)+y1 ;
hold on
% having issues with next part, trying to see if random circle has same coordinates
% as centre circle and then store its radius in matrix
if xc == xc1 and yc == yc1
z(i) = R
else end
t3 = plot(xc,yc) ; % plots random circle
set(t3(1),'color','black')
else end
end
box on
xlim([-25 25])
ylim([-25 25])

Best Answer

You can use the function inpolygon to find points inside of the larger circle. Try adding the following lines of code after t3 = plot... (at line ~38).
pts1 = inpolygon(xc,yc,xc2,yc2)
pts2 = inpolygon(xc,yc,xc1,yc1)
if sum(pts1)>=1 && sum(pts2)==0
count=count+1;
plot(xc(pts1),yc(pts1),'b.')
end
This should give you the number of circles that are inside (or partially inside) the larger circle but does not touch the inner circle (see attachment)