


INSIDEP Find all the points strictly inside an interactively draw polygon
drawn on the currently displayed plot. The plot should be
drawn with xg and yg as dots before.
USAGE ind=insidep(xg,yg);
xg = x locations of points
yg = y locations of points
Example: x=rand(20,1);y=rand(20,1);
plot(x,y,'kx');
ind=insidep(x,y);
(then click continuously with left mouse to
draw polygon until done, then click right mouse
to compute points inside.)

0001 function ind=insidep(xg,yg); 0002 % INSIDEP Find all the points strictly inside an interactively draw polygon 0003 % drawn on the currently displayed plot. The plot should be 0004 % drawn with xg and yg as dots before. 0005 % 0006 % USAGE ind=insidep(xg,yg); 0007 % 0008 % xg = x locations of points 0009 % yg = y locations of points 0010 % 0011 % Example: x=rand(20,1);y=rand(20,1); 0012 % plot(x,y,'kx'); 0013 % ind=insidep(x,y); 0014 % (then click continuously with left mouse to 0015 % draw polygon until done, then click right mouse 0016 % to compute points inside.) 0017 % 0018 0019 [x,y]=draw; 0020 n=length(x); 0021 x(n+1)=x(1); 0022 y(n+1)=y(1); 0023 line(x,y,'color','cyan','linestyle','o','erasemode','none') 0024 line(x,y,'color','cyan','linestyle','-','erasemode','none') 0025 % 0026 ind=inside(xg,yg,x,y); 0027 % 0028 % ind=0 outside polygon 0029 % ind=1 inside 0030 % ind=2 on exterior edge 0031 % ind=4 on exterior vertex 0032 % 0033 line(xg(ind==1),yg(ind==1),'color','green','linestyle','o','erasemode','none') 0034 line(xg(ind==2),yg(ind==2),'color','red','linestyle','o','erasemode','none') 0035 line(xg(ind==4),yg(ind==4),'color','white','linestyle','o','erasemode','none') 0036 % 0037 % return indices of inside points only 0038 % 0039 ind=find(ind==1); 0040 hold off