0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 clf;
0012
0013
0014
0015 xgp=[0:30]/30*2-1;
0016 ygp=xgp';
0017
0018 tol=(xgp(2)-xgp(1))/3;
0019
0020 xg=ones(size(ygp))*xgp;
0021 yg=ygp*ones(size(xgp));
0022 xg=xg(:); yg=yg(:);
0023
0024 pts=plot(xg,yg,'.k','EraseMode','none');
0025 axis([-1 1 -1 1]);
0026 set(gca,'xticklabels',' ');
0027 set(gca,'yticklabels',' ');
0028 title('Left button = new point, Right button = done');
0029 drawnow
0030 hold on
0031
0032
0033
0034 gpt=line(0,0,'Linestyle','.','Erasemode','none');
0035
0036 set(pts,'XData',0,'YData',0);
0037
0038 x=[];
0039 y=[];
0040
0041 disp('Left button for new point, right button to finish making polygon');
0042
0043 [x,y,button]=ginput(1);
0044 set(gpt,'XData',x,'YData',y,'LineStyle','+','Color','r');drawnow
0045 [xx,yy,button]=ginput(1);
0046 while (button ~=3),
0047 x=[x;xx];
0048 y=[y;yy];
0049 set(gpt,'XData',x,'YData',y,'LineStyle','-','Color','r');drawnow
0050 [xx,yy,button]=ginput(1);
0051 end;
0052
0053
0054
0055 ind=inside(xg,yg,x,y,tol);
0056
0057
0058 set(pts,'XData',xg,'YData',yg);
0059 line('XData',xg(ind==1),'YData',yg(ind==1),'Linestyle','+','Color','g','Erasemode','none');
0060 line('Xdata',xg(ind==2),'YData',yg(ind==2),'Linestyle','o','Color','r','Erasemode','none');
0061 drawnow
0062
0063 hold off