本文整理匯總了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)