I’m trying to use path.Path.contains_point for point-in-polygon testing and am running into a few different confusing situations. My specific issues/questions are:
-
I’m seeing different behaviour dependent on path direction (clockwise or counter-clockwise). Is there a “correct” direction to use?
-
What is the expected behaviour for Path.contains_point when the point is on a boundary?
-
What is the radius parameter supposed to do? The docs say it “allows the path to be made slightly larger or smaller”, but I’m clearly not understanding this properly (see the cw_path hit test failure with r=0.1 below).
Here is a short example showing some issues with a unit rectangle…
from matplotlib.path import Path
cw_path = Path([[0,0], [0,1], [1,1], [1,0]])
ccw_path = Path([[0,0], [1,0], [1,1], [0,1]])
#Point on x axis not detected for either path…
… cw_path.contains_point([0.5, 0])
0
ccw_path.contains_point([0.5, 0])
0
#Add a large radius and ccw_path works, but not cw_path (!!?)…
… r = 0.1
cw_path.contains_point([0.5, 0], radius=r)
0
ccw_path.contains_point([0.5, 0], radius=r)
1
The following ipython notebook has more detailed tests, but the main points are in the sample above.
http://nbviewer.ipython.org/7e1b347b8b21b338bee1
I’ve found at least one reference [1] online indicating that “this function is intended for use when mouse-clicking”. Does that mean I should not use it for generic point-in-polygon testing?
Thanks,
Russ