在Sympy中,函數Polygon.cut_section()用於獲取分別位於相交線上方和下方的兩個多邊形段(多邊形的two-part)的元組。它僅返回由線相交的多邊形的兩個部分。當線上方或線下方不存在多邊形時,返回None。
用法:Polygon.cut_section(line) 返回: 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
範例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)
輸出:
(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)))
範例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)
輸出:
(Triangle(Point2D(0, 2), Point2D(0, 1), Point2D(1, 2)), Polygon(Point2D(0, 1), Point2D(0, 0), Point2D(1, 0), Point2D(1, 2)))
相關用法
- Python sympy.eye()用法及代碼示例
- Python sympy.Add()用法及代碼示例
- Python sympy.ones()用法及代碼示例
- Python sympy.Mod()用法及代碼示例
- Python sympy.crt()用法及代碼示例
- Python sympy.Add()用法及代碼示例
- Python sympy.lcm()用法及代碼示例
- Python sympy.gcd()用法及代碼示例
- Python sympy.Mul()用法及代碼示例
- Python sympy.det()用法及代碼示例
- Python sympy.cos()用法及代碼示例
- Python sympy.sin()用法及代碼示例
- Python sympy.log()用法及代碼示例
- Python sympy.Pow()用法及代碼示例
- Python sympy.cot()用法及代碼示例
- Python sympy.nT()用法及代碼示例
- Python sympy.csc()用法及代碼示例
- Python sympy.has()用法及代碼示例
- Python sympy.tan()用法及代碼示例
- Python sympy.S()用法及代碼示例
注:本文由純淨天空篩選整理自ravikishor大神的英文原創作品 Python – Sympy Polygon.cut_section() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。