Python – Sympy Polygon.encloses_point() method
In Sympy, the function Polygon.encloses_point() is used to check whether the given point is enclosed by polygon or not. It returns True if the given point lies inside of the polygon, otherwise False. Being on the border of the polygon is also considered False.
Syntax: Polygon.encloses_point(p) Parameters: p: Point Returns: True: if point lies inside polygon, otherwise False.
Example #1:
Python3
# import sympy import Point, Polygon from sympy import Point, Polygon # creating points using Point() p1, p2, p3 = map (Point, [( 0 , 0 ), ( 5 , 0 ), ( 5 , 5 )]) # creating polygon using Polygon() poly = Polygon(p1, p2, p3) # using encloses_point() isEnclosed = poly.encloses_point(Point( 2 , 1 )) print (isEnclosed) |
Output:
True
Example #2:
Python3
# import sympy import Point, Polygon from sympy import Point, Polygon # creating points using Point() p1, p2, p3 = map (Point, [( 0 , 0 ), ( 4 , 0 ), ( 4 , 4 )]) # creating polygon using Polygon() poly = Polygon(p1, p2, p3) # using encloses_point() isEnclosed = poly.encloses_point(Point( 2 , 2 )) print (isEnclosed) |
Output:
False
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.