Python – Sympy Polygon.encloses_point()方法
在Sympy中,函数Polygon.encloses_point()是用来检查给定的点是否被多边形所包围。如果给定的点位于多边形的内部,它将返回True,否则返回False。在多边形的边界上也被认为是假的。
语法: Polygon.encloses_point(p)
参数 :
p: Point
返回:
真:如果点位于多边形内,否则返回假。
示例 #1:
# 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)
输出:
True
示例 #2:
# 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)
输出:
False