Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
756 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...