How to deal with the collision detection between a basketball and the ring in a basketball shootout demo?? It seems very complicated if accurate collision behaviour is required.

# Collision Detection

I could imagine doing it this way:

take the 3 coordinates of ring and ball, xRing, yRing, zRing, xBall, yBall and zBall, and the radii of ring and bal, rRing and rBall.

The first thing that would have to be determined is the radius of the ‘x/z-slice’ of the ball at the position the ring is at, basically a slice of the ball in the x/z-plane at a certain y-position. For example, if the ball is exactly halfway into the ring, the radius of the slice would be the same as the radius of the ball.

That way you would only have to deal with collision between two circles on the x/z-plane.

Kinda like this:

// is a collision possible at all?

if (yBall+rBall > yRing &&

yBall-rBall < yRing &&

xBall+rBall > xRing-rRing &&

xBall-rBall < xRing+rRing &&

zBall+rBall > zRing-rRing &&

zBall-rBall > zRing+rRing)

-determine x/z-ballslice radius at yRing

-find possible collision point between

the ballslice-circle and the ring-circle

Both circles are in x/z-plane, so this should be fairly easy to deal with.

Hope this idea works (I didnt test any of it)!

You should also check www.flipcode.com. There have been several good articles on collision detection posted there.

Nate Miller

Yea, thx for your idea!! I also think it will be working! I also would like to consider the thickness of the ring. I divide the vertical diameter of the ring into 10 divisions, so that there will be ten normals for each segments of the ring for reflective direction of the rebounding ball. If it really works in practice, I must tell you!

Originally posted by Dodger:

[b]I could imagine doing it this way:

take the 3 coordinates of ring and ball, xRing, yRing, zRing, xBall, yBall and zBall, and the radii of ring and bal, rRing and rBall.

The first thing that would have to be determined is the radius of the ‘x/z-slice’ of the ball at the position the ring is at, basically a slice of the ball in the x/z-plane at a certain y-position. For example, if the ball is exactly halfway into the ring, the radius of the slice would be the same as the radius of the ball.

That way you would only have to deal with collision between two circles on the x/z-plane.

Kinda like this:

// is a collision possible at all?

if (yBall+rBall > yRing &&

yBall-rBall < yRing &&

xBall+rBall > xRing-rRing &&

xBall-rBall < xRing+rRing &&

zBall+rBall > zRing-rRing &&

zBall-rBall > zRing+rRing)

-determine x/z-ballslice radius at yRing

-find possible collision point between

the ballslice-circle and the ring-circle

Both circles are in x/z-plane, so this should be fairly easy to deal with.

Hope this idea works (I didnt test any of it)! [/b]