[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
wraps GPC.  It is licensed under LGPL and can be found at

The algorithm, explained at

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;


On Wed, Nov 30, 2005 at 06:40:08PM -0800, Henry F. Mollet wrote:
> From
> inpolygon= use David Doolin's inpoly.m, but with [analysis]
> "";>caveat
> s
> Henry

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

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]