本文整理汇总了Python中Polygon.intersects方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.intersects方法的具体用法?Python Polygon.intersects怎么用?Python Polygon.intersects使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Polygon
的用法示例。
在下文中一共展示了Polygon.intersects方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Intersect
# 需要导入模块: import Polygon [as 别名]
# 或者: from Polygon import intersects [as 别名]
def Intersect(rect1, rect2): #{{{
Width = rect1[2].x * 2
hw = Width/2 #half width
Height = rect1[2].y * 2
hh = Height/2 #half height
#A = math.radians(rect1[1])
A = rect1[1]
sina = math.sin(A)
cosa = math.cos(A)
ul1 = Vertex2(rect1[0].x - hw*cosa - hh*sina, rect1[0].y + hh*cosa - hw*sina)
ur1 = Vertex2(rect1[0].x + hw*cosa - hh*sina, rect1[0].y + hh*cosa + hw*sina)
dl1 = Vertex2(rect1[0].x - hw*cosa + hh*sina, rect1[0].y - hh*cosa - hw*sina)
dr1 = Vertex2(rect1[0].x + hw*cosa + hh*sina, rect1[0].y - hh*cosa + hw*sina)
Width = rect2[2].x * 2
hw = Width/2 #half width
Height = rect2[2].y * 2
hh = Height/2 #half height
#A = math.radians(rect2[1])
A = rect2[1]
sina = math.sin(A)
cosa = math.cos(A)
ul2 = Vertex2(rect2[0].x - hw * cosa - hh * sina, rect2[0].y + hh * cosa - hw*sina)
ur2 = Vertex2(rect2[0].x + hw * cosa - hh * sina, rect2[0].y + hh * cosa + hw*sina)
dl2 = Vertex2(rect2[0].x - hw * cosa + hh * sina, rect2[0].y - hh * cosa - hw*sina)
dr2 = Vertex2(rect2[0].x + hw * cosa + hh * sina, rect2[0].y - hh * cosa + hw*sina)
points1 = [ul1, ur1, dr1, dl1]
points2 = [ul2, ur2, dr2, dl2]
p1 = Polygon(points1)
p2 = Polygon(points2)
return p1.intersects(p2)