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?
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.
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With