# Wierd question about Collision Detection...

Im doing a little demo featuring a ball bouncing against the faces of a cube…
I wanted to know a Good way of knowing which face the ball is colliding with. Im actually making the collision test using a bouncing sphere for the ball…

If the local axes of the ball and the cube are pointing in the same directions (not independently rotated), something like this should work:

if(ball.x+ball.xm-ball.xr < cube.left | |
ball.x+ball.xm+ball.xr > cube.right)
ball.xm = -ball.xm;

if(ball.y+ball.ym-ball.yr<cube.bottom | |
ball.y+ball.ym+ball.yr > cube.top)
ball.ym = -ball.ym;

if(ball.z+ball.zm-ball.zr < cube.far | |
ball.z+ball.zm+ball.zr > cube.near)
ball.zm = -ball.zm;

ball.x += ball.xm;
ball.y += ball.ym;
ball.z += ball.zm;

drawScene();

ball.x/y/z being the ball’s position, ball.xm/ym/zm the vector of movement of the ball and ball.xr/yr/zr the 3 radii of the ball

If I’m not mistaken, the above code assumes a completely elastic and instantaneous collision. The ball does not compress, slow down, or have any of its energy absorbed by the cube or converted into heat or some other form of energy. This form of collision detection is akin to ideal photons hitting an ideal mirror.

Still, if that’s all Devon needs, this may work fine for him. All depends on how realistic he needs the physics to be.

Thx for your replies. I dont need cutting edge physics my problem is that im doing collision detection like: Take a vertex of Obj1 and test it against all the faces of Obj2. This works fine, the problem is that I need to know if Obj1 is hitting one of the top faces or one of the sides faces to do correct (not realistic) physics…