Friday, October 10, 2025
HomeLanguagesPython – Sympy Polygon.cut_section() Method

Python – Sympy Polygon.cut_section() Method

In Sympy, the function Polygon.cut_section() is used to get a tuple of two polygon segments(two-part of the polygon) that lie above and below the intersecting line respectively. It simply returns the two parts of the polygon intersected by the line. Returns None when no polygon exists above the line or below the line.

Syntax: Polygon.cut_section(line)

Returns: upper_polygon, lower_polygon: Polygon objects or None
 upper_polygon: is the polygon that lies above the given line
 lower_polygon: is the polygon that lies below the given line
 None: when no polygon exists above the line or below the line
 
Raises: 
 ValueError: When the line does not intersect the polygon

Example #1:

Python3




# import sympy import Point, Polygon, Line
from sympy import Point, Polygon, Line
  
# creating points using Point()
p1, p2, p3, p4 = map(Point, [(0, 2), (0, 0), (1, 0), (1, 2)])
  
# creating polygon using Polygon()
poly = Polygon(p1, p2, p3, p4)
  
# using cut_section()
cutSection = poly.cut_section(Line((0, 1), slope = 0))
  
print(cutSection)


Output:

(Polygon(Point2D(0, 2), Point2D(0, 1), Point2D(1, 1), Point2D(1, 2)), 
 Polygon(Point2D(0, 1), Point2D(0, 0), Point2D(1, 0), Point2D(1, 1)))

Example #2:

Python3




# import sympy import Point, Polygon, Line
from sympy import Point, Polygon, Line
  
# creating points using Point()
p1, p2, p3, p4 = map(Point, [(0, 2), (0, 0), (1, 0), (1, 2)])
  
# creating polygon using Polygon()
poly = Polygon(p1, p2, p3, p4)
  
# using cut_section()
cutSection = poly.cut_section(Line((0, 1), slope = 1))
  
print(cutSection)


Output:

(Triangle(Point2D(0, 2), Point2D(0, 1), Point2D(1, 2)), 
 Polygon(Point2D(0, 1), Point2D(0, 0), Point2D(1, 0), Point2D(1, 2)))
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32350 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6717 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7099 POSTS0 COMMENTS
Thapelo Manthata
6794 POSTS0 COMMENTS
Umr Jansen
6794 POSTS0 COMMENTS