MATLAB: For intersecting circles, how to remove overlap and have chord visible? Also, how to randomly generate circle position in design space

chord lengthcircle intersectionscircle overlaprandom

As in the image, I am trying to remove the circle overlap from the intersection, and have the chord itself (not present in the image) visible.

Best Answer

How are you drawing your circles?
However you are trying to draw it you'll probably end up having x and y points representing the 2 circles.
xCenter1 = 7;
yCenter1 = 7;
xCenter2 = 12;
yCenter2 = 10;
theta = 0 : 0.01 : 2*pi;
radius1 = 5;
radius2 = 6;
%generate 2 circles with parameters above.
x1 = radius1 * cos(theta) + xCenter;
y1 = radius1 * sin(theta) + yCenter;
x2 = radius2 * cos(theta) + xCenter2;
y2 = radius2 * sin(theta) + yCenter2;
%%find distance from each circle center to the other circle's infringing points.
dC1 = sqrt((x2-xCenter1).^2+(y2-yCenter1).^2)>=radius1;
dC2 = sqrt((x1-xCenter2).^2+(y1-yCenter2).^2)>=radius2;
plot(x1(dC2), y1(dC2),'b.',x2(dC1),y2(dC1),'r.');
axis square;
xlim([0 20]);
ylim([0 20]);
grid on;
Looking at your sample picture it is easy to see that the infringing portion of circle 2 into circle 1 are points that are within the radius of circle 1. (vice versa for circle 2) With this we can calculate the distance of all points of circle 2 to the center of circle 1 and compare it to the radius.