Inpolygon equivalent

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Inpolygon equivalent

Burrows,William [Edm]
Inpolygon equivalent

I would like to port a MATLAB program to Octave that calls the MATLAB
function "inpolygon". Is there an equivalent function in Octave?
Thanks -

Bill

William Burrows
Environment Canada - MSC/PNR - Science Division
Twin Atria Building, Room 200
4999 - 98 Avenue, Edmonton, Alberta, T6B 2X3
Phone: 780-951-8803          Fax: 780-495-3529
 e-mail: [hidden email]



Reply | Threaded
Open this post in threaded view
|

Re: Inpolygon equivalent

Joe Koski
Re: Inpolygon equivalent Bill,

When I have a problem like this, I go to the MathWorks at http://www.mathworks.com/access/helpdesk/help/helpdesk.shtml and find out exactly what the routine does. Then I go to the octave-forge combined index at http://octave.sourceforge.net/index/index.html and look for routines that do the same thing. Often you can get things going faster that way than you can waiting for a reply, although I’m sure somebody out there knows the answer.

Joe

on 11/30/05 3:52 PM, Burrows,William [Edm] at [hidden email] wrote:

I would like to port a MATLAB program to Octave that calls the MATLAB
function "inpolygon". Is there an equivalent function in Octave?
Thanks -


Bill

William Burrows
Environment Canada - MSC/PNR
- Science Division
Twin Atria Building, Room 200
4999 - 98 Avenue, Edmonton, Alberta, T6B 2X3
Phone: 780-951-8803          Fax: 780-495-3529
 e-mail: [hidden email]





Reply | Threaded
Open this post in threaded view
|

Re: Inpolygon equivalent

Henry F. Mollet
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



on 11/30/05 5:36 PM, Joe Koski at [hidden email] wrote:

> Bill,
>
> When I have a problem like this, I go to the MathWorks at
> http://www.mathworks.com/access/helpdesk/help/helpdesk.shtml and find out
> exactly what the routine does. Then I go to the octave-forge combined index
> at http://octave.sourceforge.net/index/index.html and look for routines that
> do the same thing. Often you can get things going faster that way than you
> can waiting for a reply, although I¹m sure somebody out there knows the
> answer.
>
> Joe
>
> on 11/30/05 3:52 PM, Burrows,William [Edm] at [hidden email]
> wrote:
>
>> I would like to port a MATLAB program to Octave that calls the MATLAB
>> function "inpolygon". Is there an equivalent function in Octave?
>> Thanks -
>>
>> Bill
>>
>> William Burrows
>> Environment Canada - MSC/PNR - Science Division
>> Twin Atria Building, Room 200
>> 4999 - 98 Avenue, Edmonton, Alberta, T6B 2X3
>> Phone: 780-951-8803          Fax: 780-495-3529
>>  e-mail: [hidden email]
>>
>>
>>
>
>





-------------------------------------------------------------
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
-------------------------------------------------------------

Reply | Threaded
Open this post in threaded view
|

Re: Inpolygon equivalent

Stéfan van der Walt
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

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
-------------------------------------------------------------