Programming/수학&물리

사각형과 원의 충돌체크

Jiung. 2015. 12. 10. 02:35
반응형
1
2
3
4
5
6
7
8
9
10
11
y    = Math.abs(circle.y - (rect.y+rect.hight));
if (y < circle.r && circle.x > rect.x && circle.x < rect.x + rect.width)
{
    // check
}
 
y    = Math.abs(circle.y - rect.y);
if (y < circle.r && circle.x > rect.x && circle.x < rect.x + rect.width)
{
    // check
}
cs


x축에 관한 충돌 처리는 위의 코드를 x축으로 바꾸면 된다.

반응형