Python – Sympy Polygon.encloses_point() 方法
在 Sympy 中,函数Polygon.encloses_point ()用于检查给定点是否被多边形包围。如果给定点位于多边形内部,则返回 True,否则返回 False。在多边形的边界上也被认为是 False。
Syntax: Polygon.encloses_point(p)
Parameters:
p: Point
Returns:
True: if point lies inside polygon, otherwise False.
示例 #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)
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)
输出:
True
示例 #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)
输出:
False