Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Point inside polygon

Tags:

numpy

scipy

I'm looking for a way to determine whether a particular point is within a polygon given its vertices using NumPy/SciPy.

I haven't been able to find one online. Is there even a way to do this using NumPy/SciPy?

like image 540
High schooler Avatar asked Feb 06 '14 20:02

High schooler


People also ask

How do you find a point inside a polygon?

One simple way of finding whether the point is inside or outside a simple polygon is to test how many times a ray, starting from the point and going in any fixed direction, intersects the edges of the polygon. If the point is on the outside of the polygon the ray will intersect its edge an even number of times.

What is interior point in polygon?

An interior angle of a polygon is an angle formed inside the two adjacent sides of a polygon. Or, we can say that the angle measures at the interior part of a polygon are called the interior angle of a polygon.

Is a point inside a convex polygon?

A convex polygon is a simple polygon (with no self intersections) such that any line segment between two points inside of the polygon lies completely inside of it. The point will be inside a convex polygon if and only if it lies on the same side of the support line of each of the segments.

How do you know if a point is inside?

The simplest way to determine if a point lies inside a triangle is to check the number of points in the convex hull of the vertices of the triangle adjoined with the point in question. If the hull has three points, the point lies in the triangle's interior; if it is four, it lies outside the triangle.


1 Answers

Have you considered Shapely? Just create a Polygon and check if polygon contains a point.

>>> from shapely.geometry import Point
>>> from shapely.geometry.polygon import Polygon

>>> point = Point(0.5, 0.5)
>>> polygon = Polygon([(0, 0), (0, 1), (1, 1), (1, 0)])
>>> polygon.contains(point)
True
>>> point2 = Point((10, 10))
>>> polygon.contains(point2)
False
like image 175
arkottke Avatar answered Sep 19 '22 05:09

arkottke