2
我想在Zelle的python圖形模塊中構建一個2D地圖。 我使用Polygon類對象創建了地圖邊界。 如果我想檢查圓形物體是否正在觸摸地圖邊界以檢測碰撞,我應該怎麼做?Python碰撞檢測,不在pygame
這是我的意思的例子:
poly = Polygon(Point(x1,y1), Point(x2,y2), Point(x3,y3)) .draw(win) # a triangle shape
circ = Circle (Point(x4,y4), radius) .draw(win) # drawn in the middle of the triangle map
我可以用circ.getCenter()
得到circ
現在的位置,但我不知道什麼是檢查兩個對象是否穿越的最佳途徑。也許是這樣的
def collision(circ,poly,x,y):
if position of circle passes the position of the line of the poly at x,y:
detect collision
else:
pass
可能重複http://stackoverflow.com/questions/1073336 /圓形線碰撞檢測) – martineau
請注意,您也許可以通過做一些高級檢查來改進對「圓線碰撞檢測」問題的接受答案 - 例如,如果中心距包圍多邊形的所有點的虛圓大於兩個圓的半徑之和。 – martineau