在Sympy中,函數Polygon.intersection()用於獲取給定多邊形和給定幾何實體的交集。幾何實體可以是點,線,多邊形或其他幾何圖形。如果多邊形和給定的幾何實體未在任何地方相交,則交點可以為空。但是,如果存在相交,則可以包含單個點或完整的線段。
用法:Polygon.intersection(o) 參數:Geometry Entity 返回:The list of Segments or Points of intersection.
範例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)])
p5, p6, p7 = map(Point, [(3, 2), (1, -1), (0, 2)])
# creating polygons using Polygon()
poly1 = Polygon(p1, p2, p3, p4)
poly2 = Polygon(p5, p6, p7)
# using intersection()
isIntersection = poly1.intersection(poly2)
print(isIntersection)
輸出:
[Point2D(1/3, 1), Point2D(2/3, 0), Point2D(9/5, 1/5), Point2D(7/3, 1)]
範例2:
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()
poly1 = Polygon(p1, p2, p3, p4)
# using intersection()
isIntersection = poly1.intersection(Line(p1, Point(3, 2)))
print(isIntersection)
輸出:
[Point2D(0, 0), Point2D(3/2, 1)]
相關用法
- Python sympy.rf()用法及代碼示例
- Python sympy.log()用法及代碼示例
- Python sympy.nT()用法及代碼示例
- Python sympy.Add()用法及代碼示例
- Python sympy.crt()用法及代碼示例
- Python sympy.Mul()用法及代碼示例
- Python sympy.Add()用法及代碼示例
- Python sympy.tan()用法及代碼示例
- Python sympy.sin()用法及代碼示例
- Python sympy.Pow()用法及代碼示例
- Python sympy.div()用法及代碼示例
- Python sympy.nC()用法及代碼示例
- Python sympy.nP()用法及代碼示例
- Python sympy.ff()用法及代碼示例
- Python sympy.S()用法及代碼示例
- Python sympy.csc()用法及代碼示例
- Python sympy.apart()用法及代碼示例
- Python sympy.Mod()用法及代碼示例
- Python sympy.gcd()用法及代碼示例
- Python sympy.cot()用法及代碼示例
注:本文由純淨天空篩選整理自ravikishor大神的英文原創作品 Python – Sympy Polygon.intersection() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。