For intersecting circles, how to remove overlap and have chord visible? Also, how to randomly generate circle position in design space?
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (2)
Roger Stafford
el 9 de Jun. de 2014
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
1 comentario
Sean
el 10 de Jun. de 2014
Kelly Kearney
el 9 de Jun. de 2014
0 votos
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.
Categorías
Más información sobre Triangulations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!