Home > RPSstuff > indemo.m

indemo

PURPOSE ^

INDEMO Demo program for function INSIDE

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 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.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % INDEMO   Demo program for function INSIDE
0002 %          This script file lets you draw a polygon using the mouse, then
0003 %          it shows which points on a (blue) grid are inside the polygon.
0004 %
0005 
0006 %RP (WHOI) 19/Dec/91
0007 %          Updated for Matlab 4.0 7/nov/92
0008 
0009 % updated to version 5.1 AN
0010       
0011 clf;
0012 
0013    % create the grid
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    % make the polygon using the mouse
0032 
0033     % Make a graphic object for the polygon
0034 gpt=line(0,0,'Linestyle','.','Erasemode','none');
0035     % Temporarily get rid of the grid points for speed
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    % do the work
0054 
0055 ind=inside(xg,yg,x,y,tol); % low tolerance to make edges appear more frequently
0056 
0057    % put the grid back in, and add the results.
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

Generated on Wed 30-Nov-2005 14:45:02 by m2html © 2003