From octave-sources-request at bevo dot che dot wisc dot edu Sat Mar 27 02:19:20 1999 Subject: Re: inpoly.m clean up From: Ariel Tankus To: doolin at cs dot utk dot edu (David Doolin) Cc: octave-sources at bevo dot che dot wisc dot edu Date: Sat, 27 Mar 1999 10:19:27 +0200 (GMT+0200) > > > Code clean, documentation clean, minor > corrections. > > > ----------------snip snap------------ > > % [ inside ] = inpoly(polygon, point) > % > % Determines whether a given point is inside a polygon. > % The polygon is determined by point pairs on its > % boundary. There is no error checking, and to be safe > % only use convex polygons. > % > % input: > % polygon: column vector of (x,y) pairs representing the vertex > % points of the polygon. > % point: (x,y) pair representing point that is either > % in or out of the polygon > % > % output: > % inside: boolean true for inside, false otherwise. > % > % todo: > % Implement the ability to handle an array of points > % and return an array of boolean values. > % > % bugs and limitations: > % > % Need to check whether convexity is a necessary > % condition for this algorithm (don't think it is). > % > % Behavior with multiple loops, i.e., if sides cross > % over, is unknown. > % > % Algorithm implemented in integer, first quadrant > % numbers. Need to check generality of algorithm. > % > % Points on the boundaries of polygons may not be handled > % correctly or consistently. > > % > % This code was derived from a public domain code > % copyright 1995-1996 Galacticomm, Inc., modifications > % allowed for any purpose provided redistribution is > % not restricted > % > % This script properly belongs in octave/compgeom/ > % (computational geometry). > % > % This modified code is copyright David M. Doolin and placed in > % the public domain, with the exception that redistribution > % is not restricted in accordance with the copyright of unmodified > % (original) C code. > % > % $Author: doolin $ doolin at ce dot berkeley dot edu > % $Date: 1999/03/26 18:42:00 $ > % $Source: /shag/homes/doolin/cvsroot/octave/compgeom/inpoly.m,v $ > % $Revision: 1.2 $ > I suggest some minor but very important changes before the code is included in the distribution. The important change is the name of the function. It is called: inpolygon in MATLAB, and in my opinion, we should follow the naming convention. In addition, the parameters received by the function do not follow MATLAB's. MATLAB uses: in = inpolygon(x,y,xv,yv) where x and y are matrices of coordinates (x(p,q), y(p,q)) and xv and yv are the coordinates of the polygon. I understand that (x,y) being matrices is still not supported, and this indeed can be a future task. Though I find *your* input format more convenient, I still think the input format should match MATLAB's, so the users do not get used to a different interface, which is difficult to change in the future. I do think, however, that leaving your interface as an additional option is a good idea (switching the position of the polygon and point: point should be the first argument). -- Ariel Tankus Tel-Aviv University.