Python – Sympy Polygon.is_convex() 方法
在 Sympy 中,函数Polygon.is_convex ()用于检查给定多边形是否为凸多边形。如果多边形的所有内角都小于 180 度并且边之间没有相交,则称该多边形为凸多边形。
Syntax: Polygon.is_convex()
Returns:
True: True if this polygon is convex, False otherwise.
示例 #1:
Python3
# import Point, Polygon
from sympy import Point, Polygon
# creating points using Point()
p1, p2, p3, p4 = map(Point, [(0, 0), (1, 0), (5, 1), (0, 1)])
# creating polygon using Polygon()
isConvex = Polygon(p1, p2, p3, p4)
# using is_convex()
print(isConvex.is_convex())
Python3
# import Point, Polygon
from sympy import Point, Polygon
# creating points using Point()
p1, p2, p3, p4, p5 = map(Point, [(0, 0), (3, 2), (4, 5), (7, 1), (6, 3)])
# creating polygon using Polygon()
isConvex = Polygon(p1, p2, p3, p4, p5)
# using is_convex()
print(isConvex.is_convex())
输出:
True
示例 #2:
Python3
# import Point, Polygon
from sympy import Point, Polygon
# creating points using Point()
p1, p2, p3, p4, p5 = map(Point, [(0, 0), (3, 2), (4, 5), (7, 1), (6, 3)])
# creating polygon using Polygon()
isConvex = Polygon(p1, p2, p3, p4, p5)
# using is_convex()
print(isConvex.is_convex())
输出:
False