matlab - Determine if the user clicked inside the polygon or outside of it -


i trying write script in matlab fills polygon , prints "inside" output window when user clicks inside polygon , "outside" output window when user clicks outside polygon. reason prints inside when click outside polygon. have put code below.

xv = [ -3 3 3 -3]; %// x coords of polygon vertices. arbitrary number yv = [-5 -5 7 7]; %// y coords of polygon vertices. same number x fill(xv,yv,'b') %// draw polygon axis([-10 10 -10 10]) [xp, yp] = ginput(1); %// point coordinates inside = inpolygon(xp,yp,xv,yv); %// inside?  while inside     fprintf('inside\n')     [xp, yp] = ginput(1); end     fprintf('outside\n') 

the code missing line in while loop reset value of inside, checking see if user input still in polygon:

while inside     fprintf('inside\n')     [xp, yp] = ginput(1);     inside = inpolygon(xp,yp,xv,yv); %// inside? end  % outside polygon, finished fprintf('outside\n') 

and once user has clicked outside polygon, script terminates.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -