当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Python Sympy Polygon.intersection()用法及代码示例


在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)]



相关用法


注:本文由纯净天空筛选整理自ravikishor大神的英文原创作品 Python – Sympy Polygon.intersection() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。