Check if the points are inside the convex body
I am making a convex hull using the package scipy.spatial
http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.ConvexHull.html#scipy.spatial.ConvexHull
I tried searching but don't know yet if there is an easy way to find if any point (latitude / longitude) is inside a convex hull. Any suggestions?
source to share
The method I used earlier uses the class Path
matplotlib
. This is the method contains_point
that does exactly that. Also like contains_points
, which allows you to query an array of points.
To use this, you will do
from scipy.spatial import ConvexHull
from matplotlib.path import Path
hull = ConvexHull( points )
hull_path = Path( points[hull.vertices] )
print hull_path.contains_point((1,2)) # Is (1,2) in the convex hull?
source to share