Re: [Matplotlib-users] matplotlib.nxutils.pnpoly returns True for some vertexes, and False for others

2013-01-30 Thread Benjamin Root
On Tue, Jan 29, 2013 at 5:55 PM, Maria Liukis liu...@usc.edu wrote:

 Hello,

 I tested the following code on my Mac laptop and our production Linux
 server both running matplotlib V1.0.1. Both machines observe the same
 output from the code, so I was wondering if somebody is aware of the
 problem or if it's some undocumented feature of pnpoly() function from
 matplotlib.nxutils?

 I use matplotlib.nxutils.pnpoly() function from matplotlib to determine
 if point belongs to the polygon.
 The following code:

  import numpy as np
  import matplotlib.nxutils as nx
  coords = np.array([[4.0, 1.0], [4.0, 4.0], [5.0, 5.0], [6.0, 4.0],
 [5.0, 0.0]])

  nx.pnpoly(4.0, 1.0, coords)
 1
  nx.pnpoly(4.0, 4.0, coords)
 1
  nx.pnpoly(5.0, 5.0, coords)
 0
  nx.pnpoly(6.0, 4.0, coords)
 0
  nx.pnpoly(5.0, 0.0, coords)
 0

 The question is why first two vertexes are considered to be inside of
 defined polygon, and last 3 vertexes are not? My guess, it's treating the
 polygon as a semi-open set, and I wonder if it can be changed to make all
 vertexes inclusive?

 Any help would be greatly appreciated.

 Many thanks,
 Masha


The documentation for pnpoly() for that version states:


A point on the boundary may be treated as inside or outside.
See `pnpoly 
http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html`_


Note that in version 1.2.0, the nxutils module was deprecated.  pnpoly()
and points_inside_poly() are now merely wrappers around the polygon's
implementations of point-testing, which differs from the nxutils'
implementation, so you may get slightly different results.

Do note that the point-testing algorithm in matplotlib was more geared for
visualization purposes rather than for strict geometric needs.  If you need
a more well-behaved point-tester (and faster if the polygon is prepared),
use the shapely package instead.

I hope that clears things up!

Cheers!
Ben Root
--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] matplotlib.nxutils.pnpoly returns True for some vertexes, and False for others

2013-01-30 Thread Maria Liukis
Ben,

Many thanks! Will try to use shapely package then.

Masha

liu...@usc.edu




On Jan 30, 2013, at 6:59 AM, Benjamin Root wrote:

 
 
 On Tue, Jan 29, 2013 at 5:55 PM, Maria Liukis liu...@usc.edu wrote:
 Hello,
 
 I tested the following code on my Mac laptop and our production Linux server 
 both running matplotlib V1.0.1. Both machines observe the same output from 
 the code, so I was wondering if somebody is aware of the problem or if it's 
 some undocumented feature of pnpoly() function from matplotlib.nxutils?
 
 I use matplotlib.nxutils.pnpoly() function from matplotlib to determine if 
 point belongs to the polygon. 
 The following code:
 
  import numpy as np
  import matplotlib.nxutils as nx
  coords = np.array([[4.0, 1.0], [4.0, 4.0], [5.0, 5.0], [6.0, 4.0], [5.0, 
  0.0]])
 
  nx.pnpoly(4.0, 1.0, coords)
 1
  nx.pnpoly(4.0, 4.0, coords)
 1
  nx.pnpoly(5.0, 5.0, coords)
 0
  nx.pnpoly(6.0, 4.0, coords)
 0
  nx.pnpoly(5.0, 0.0, coords)
 0
 
 The question is why first two vertexes are considered to be inside of defined 
 polygon, and last 3 vertexes are not? My guess, it's treating the polygon as 
 a semi-open set, and I wonder if it can be changed to make all vertexes 
 inclusive?
 
 Any help would be greatly appreciated.
 
 Many thanks,
 Masha
 
 The documentation for pnpoly() for that version states:
 
 
 A point on the boundary may be treated as inside or outside.
 See `pnpoly 
 http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html`_
 
 
 Note that in version 1.2.0, the nxutils module was deprecated.  pnpoly() and 
 points_inside_poly() are now merely wrappers around the polygon's 
 implementations of point-testing, which differs from the nxutils' 
 implementation, so you may get slightly different results.
 
 Do note that the point-testing algorithm in matplotlib was more geared for 
 visualization purposes rather than for strict geometric needs.  If you need a 
 more well-behaved point-tester (and faster if the polygon is prepared), use 
 the shapely package instead.
 
 I hope that clears things up!
 
 Cheers!
 Ben Root
 

--
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users