help-octave
[Top][All Lists]

## Re: Inpolygon equivalent

 From: Stefan van der Walt Subject: Re: Inpolygon equivalent Date: Thu, 1 Dec 2005 09:52:19 +0200 User-agent: Mutt/1.5.9i

```Octave-forge includes non-free bindings to the General Polygon
Clipping library, which makes this fairly easy to implement.

The following code comes from the Polygon-module for Python, that

http://www.dezentral.de/soft/Polygon

The algorithm, explained at

http://graphics.cs.ucdavis.edu/~okreylos/TAship/Spring2000/PointInPolygon.html

is elegant and simple, and can easily be implemented in octave.

int poly_c_point_inside(gpc_vertex_list *vl, double x, double y){
int i, j, c=0;
gpc_vertex *vi, *vj;
for (i=0, j=vl->num_vertices-1; i < vl->num_vertices; j = i++) {
vi = vl->vertex+i;
vj = vl->vertex+j;
if ((((vi->y <= y) && (y < vj->y)) || ((vj->y <= y) && (y < vi->y))))
if ((x < (vj->x - vi->x) * (y - vi->y) / (vj->y - vi->y) + vi->x))
c = !c;
}
return c;
}

Regards
Stéfan

On Wed, Nov 30, 2005 at 06:40:08PM -0800, Henry F. Mollet wrote:
> From http://octave.sourceforge.net/index/index.html:
>
> inpolygon= use David Doolin's inpoly.m, but with [analysis]
> "http://www.che.wisc.edu/octave/mailing-lists/octave-sources/1999/13";>caveat
> s
>
> Henry

-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------

```