In Sympy, the function Polygon.is_convex() is used to check whether the given polygon is convex or not. A polygon is said to be convex if all its interior angles are less than 180 degrees and there are no intersections between the sides.
Syntax: Polygon.is_convex() Returns: True: True if this polygon is convex, False otherwise.
Example #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()) |
Output:
True
Example #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()) |
Output:
False