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

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.

5 Comments

In terms of the overlap, the arc present from any circle that is inside of another circle should be removed, and the overlapped area should be removed as well.
The pair does not have the chord length (line segment connecting the two intersection points), which I have already discovered how to implement. The assistance I require is in removing the arc that overlaps another circle (the arc of one circle inside of another's boundary, or radius).

Sign in to comment.

 Accepted 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.

More Answers (2)

Let P1 = [x1;y1] and P2 = [x2;y2] be column vectors for the coordinates of the two centers of the circles and let r1 and r2 be their respective radii.
d2 = sum((P2-P1).^2);
P0 = (P1+P2)/2+(r1^2-r2^2)/d2/2*(P2-P1);
t = ((r1+r2)^2-d2)*(d2-(r2-r1)^2);
if t <= 0
fprintf('The circles don''t intersect.\n')
else
T = sqrt(t)/d2/2*[0 -1;1 0]*(P2-P1);
Pa = P0 + T; % Pa and Pb are circles' intersection points
Pb = P0 - T;
a = atan2(P1(2)-P2(2),P1(1)-P2(1));
b1 = atan2(abs(det([Pa-P1,P1-P2])),dot(Pa-P1,P1-P2));
b2 = atan2(abs(det([Pb-P2,P2-P1])),dot(Pb-P2,P2-P1));
t1 = linspace(a-b1,a+b1);
t2 = linspace(a+pi-b2,a+pi+b2);
Q1 = bsxfun(@plus,P1,r1*[cos(t1);sin(t1)]);
Q2 = bsxfun(@plus,P2,r2*[cos(t2);sin(t2)]);
plot(Q1(1,:),Q1(2,:),'y-',Q2(1,:),Q2(2,:),'y-',...
[Pa(1),Pb(1)],[Pa(2),Pb(2)],'y-')
axis equal
end
If you have the mapping toolbox, try polybool. If you don't, try this option, which appears to do provide a wrapper around GPC, which is the same thing polybool does.

Categories

Find more on Computational Geometry in Help Center and File Exchange

Asked:

on 5 Jun 2014

Commented:

on 10 Jun 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!