% Schematic5.m
clear; clf; N=15;h=1/N;
for i=1:N
    x(i)=(i-1)*h;
end
y=x; x2=linspace(0,1,N+1);y2=x2;
figure(1); hold;
for i=1:N
    for j=1:N
        plot(x(i),y(j),'.', 'Markersize', 28)
    end
end
clf;
for j=1:N+1
    line([x2(1) x2(end)],[y2(j) y2(j)],'color','k')
    line([x2(j) x2(j)],[y2(1) y2(end)],'color','k')
end
for i=1:N
    for j=1:N
        d(i,j)=0.27-sqrt((x(i)-0.5)^2+(y(j)-0.5)^2);
        if (abs(d(i,j))<1.01*sqrt(2)*h)
            u(i,j)=0;
        else
            u(i,j)=1;
        end
    end
end
v=0*u;
for i=2:N-1
    for j=2:N-1
      if ((abs(u(i+1,j)-u(i-1,j))+abs(u(i,j+1)-u(i,j-1)))*u(i,j)>0.5)
            v(i,j)=1000;
      else
            v(i,j)=0;
      end
    end
end
dx=0*d; dy=0*d; fig1=figure(1); hold on; s=0.5*h; dd=-abs(d);
for i=2:N-1
    for j=2:N-1
        if (v(i,j)>0.5)
            plot(x(i),y(j),'ko', 'Markersize', 9)
            dx(i,j)=(dd(i+1,j)-dd(i-1,j))/(2*h);
            dy(i,j)=(dd(i,j+1)-dd(i,j-1))/(2*h);
        end
    end
end
for i=2:N-1
    for j=2:N-1
        if (v(i,j)>0.5)
            dx(i,j)=(dd(i+1,j)-dd(i-1,j))/(2*h);
            dy(i,j)=(dd(i,j+1)-dd(i,j-1))/(2*h);
        end
    end
end
for i=2:N-1
    for j=2:N-1
        if (u(i,j)==0)
            plot(x(i),y(j),'k.', 'Markersize', 25)
        end
    end
end
line([x2(7) x2(11)],[y2(3) y2(3)],'color','k','linewidth',5)
line([x2(7) x2(7)],[y2(3) y2(7)],'color','k','linewidth',5)
line([x2(7) x2(11)],[y2(7) y2(7)],'color','k','linewidth',5)
line([x2(11) x2(11)],[y2(3) y2(7)],'color','k','linewidth',5)
[xx,yy]=meshgrid(x,y); contour(xx,yy,d,[0 0],'k', 'linewidth', 2);
axis image; axis off; view(0,90);