If you have two circle origins with radius:
Pt1 = [20 30];
Pt2 = [15 20];
rad1 = 7;
rad2 = 12;
You can determine if they overlap by checking the distance between the points. If that distance is greater than the sum of their radii, then they overlap:
pt2ptDist = sqrt(sum((Pt1-Pt2).^2));
if pt2ptDist < rad1+rad2
disp('HIT!')
end
But in your code, you never store the origins of the circles... you only draw them:
for ctt = 1:number_shots
drawCircle(1,[(rand*(xmax +10) -5) rand*(ymax-5)],xmin,xmax,ymin,ymax,'k');
end
Instead, you should store the variable locations and use the formula I gave above to determine if each stored location makes a hit with the other circles.
Best Answer