AI Basket Ball

Simulations Require Mathematics

If you are curious, you can find an explanation here.

If you are really smart at maths, please help me ensure it is correct.

One thing it doesn’t cover is the small issue of collisions (floor, backboard, rim). And this takes some fun getting to work. I won’t claim every possible ball angle complies with the laws of physics. It’s good enough for the AI but requires better testing and tweaks if it were a paid-for game.

Deflection is the angle of incidence equals the angle of reflection. Restitution is the impact of the bounce, which leads to the ball losing some momentum.

If the ball’s bottom touches or goes through the floor(!), we flip the vertical velocity and apply a coefficient of restitution (0.6) that slows the ball.

If the ball touches the backboard we reverse the horizontal velocity, again applying a coefficient of restitution.

  • If the ball hits the rim, we need to make the ball deflect. Directionality depends on where the ball is coming from is heading to. If it hits the inside of the rim as the ball goes downwards, the ball carries on. Again deflections include restitution.

Like this, it hit the hoop (intentionally), and you’ll notice it bounces.

But sometimes it can go in after hitting the backboard or hoop.

Please stop showing off, Abcde.

It needs to detect when a ball goes through the hoop. One may take for granted – directionality matters. It must arrive above the hoop and then also go below the hoop. I mention it because I failed to consider it, and Abcde was unimpressed.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *