% illusion no 1: le triangle de Kanizsa

% cercle
t=0:pi/200:2*pi;
r=0.3;
x=r*cos(t);
y=r*sin(t);

% centres des cercles
tc=pi/2:2*pi/3:2*pi+pi/2;
xc=cos(tc);
yc=sin(tc);

f=0.7;
A=[xc(1) yc(1)];
B=[f*(xc(2)+xc(1))/2 f*(yc(2)+yc(1))/2];
C=[xc(2) yc(2)];
[xx,yy,rr]=cercle3pts(A,B,C);
d1=2*pi+atan2(yc(1)-yy,xc(1)-xx);
a1=2*pi+atan2(yc(2)-yy,xc(2)-xx);
t1=d1:-pi/200:a1;
x1=rr*cos(t1)+xx;
y1=rr*sin(t1)+yy;
A=[xc(2) yc(2)];
B=[f*(xc(2)+xc(3))/2 f*(yc(2)+yc(3))/2];
C=[xc(3) yc(3)];
[xx,yy,rr]=cercle3pts(A,B,C);
d2=atan2(yc(2)-yy,xc(2)-xx);
a2=atan2(yc(3)-yy,xc(3)-xx);
t2=a2:pi/200:d2;
x2=rr*cos(t2)+xx;
y2=rr*sin(t2)+yy;
A=[xc(1) yc(1)];
B=[f*(xc(1)+xc(3))/2 f*(yc(1)+yc(3))/2];
C=[xc(3) yc(3)];
[xx,yy,rr]=cercle3pts(A,B,C);
d3=atan2(yc(1)-yy,xc(1)-xx);
a3=atan2(yc(3)-yy,xc(3)-xx);
t3=d3:pi/200:a3;
x3=rr*cos(t3)+xx;
y3=rr*sin(t3)+yy;
X=[x1 fliplr(x2) fliplr(x3)];
Y=[y1 fliplr(y2) fliplr(y3)];

% représentations
plot(xc,-yc,'k','linewidth',2)
hold on
fill(x+xc(1),y+yc(1),'k',...
     x+xc(2),y+yc(2),'k',...
	 x+xc(3),y+yc(3),'k')
fill(X,Y,'w','edgecolor','w')

set(gcf,'color','w')
axis off
axis equal
hold off
