2014-01-18 3 views
2

저는 Zelle의 파이썬 그래픽 모듈로 2D 맵을 구현하려고합니다. Polygon 클래스 객체를 사용하여 맵 경계를 만들었습니다. cirlce 오브젝트가 충돌을 감지하기 위해 맵 경계를 만지는지 확인하려면 어떻게해야합니까?파이 게임에서의 파이썬 충돌 감지

이 무슨 뜻인지의 예입니다

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 
+0

가능한 중복 http://stackoverflow.com/questions 다음 if 문에 아무것도 넣지하고이 같은, 당신이 원하는 것을 넣어 else가 문을 만들 필요가/1073336/circle-line-collision-detection) – martineau

+1

일부 높은 수준의 검사를 수행하여 "Circle line collision detection"질문에 대한 대답을 향상시킬 수도 있습니다. 예를 들어, 다각형의 모든 점을 둘러싸는 가상 원은 두 원의 반지름의 합보다 큽니다. – martineau

답변

1

나는 파이썬에서 충돌 탐지 프로그램을 발견했다. 여기있다. 이 원은지도에 닿을 경우의 0과 rect_x의 모든 모든을 교체해야합니다 감지에 도착하기 위해, 그래서 원의 가장자리, 사각형을 건 드리면

if circle_x < rect_x + circle_width and circle_x + rect_width > rect_x and circle_y < rect_y + circle_height and circle_height + circle_y > rect_height : 

그러나,이 감지 하기 위해 원 일반에지도를 터치하는 경우는 감지 이제

if circle_x < 0 + circle_width and circle_x + screen_width > 0 and circle_y < 0 + circle_height and circle_height + circle_y > screen_height : 

, : 다음과 같이 화면 폭을 갖는 rect_width 화면 높이와 rect_height를 교체 0 rect_y 원이 화면의 가장자리를 만지면 감각을 갖습니다.

if circle_x < 0 + circle_width and circle_x + screen_width > 0 and circle_y < 0 + circle_height and circle_height + circle_y > screen_height : 
    #put nothing here 
else: 
    #put the code you need here 
[원 선 충돌 감지 (의