For intersecting circles, how to remove overlap and have chord visible? Also, how to randomly generate circle position in design space?
이전 댓글 표시
채택된 답변
추가 답변 (2개)
Roger Stafford
2014년 6월 9일
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
Kelly Kearney
2014년 6월 9일
0 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Triangulations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!