% INDEMO   Demo program for function INSIDE
%          This script file lets you draw a polygon using the mouse, then
%          it shows which points on a (blue) grid are inside the polygon.
%         
clg; hold off;
axis([-1 1 -1 1]);

xgp=[0:21]/21*2-1;
ygp=xgp';

xg=ones(ygp)*xgp;
yg=ygp*ones(xgp);

xg=xg(:); yg=yg(:);

plot(xg,yg,'.g');
hold on

x=[];
y=[];

disp('Left button for new point, right button to finish making polygon');

[x,y,button]=ginput(1);
[xx,yy,button]=ginput(1);
while (button ~=3),
   x=[x;xx];
   y=[y;yy];
   plot(x,y,'-');
   [xx,yy,button]=ginput(1);
end;


ind=inside(xg,yg,x,y,.001); % low tolerance to make edges appear more frequently

plot(xg(ind==1),yg(ind==1),'+g');
plot(xg(ind==2),yg(ind==2),'or');
plot(xg(ind==4),yg(ind==4),'ow');
hold off
