Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Python – Sympy Polygon.encloses_point() method

  • Last Updated : 01 Aug, 2020

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


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!