This week, I spent the majority of my time finishing up the physics simulation. I created the function simulate_shot, which takes the state of the board and a given shot’s angle, power, and spin and then simulates how that shot would play out on an actual pool table. I spent a lot of time researching how to calculate the inelastic collision when different balls collide, and I believe I have a pretty good implementation of it. I also added optimizations to the shot simulation code, including vectorization through NumPy and handling ball collisions with spacial hashing, to get the average runtime of a single shot simulation down to ~25ms from ~75ms.
Additionally, I created a function simulate_shot_with_animation, that draws and simulates the shot onto a Matplotlib graph. This function and file take 5 consecutive shots with random power, angle, and spin and show the state of the board during and after each shot. I used this testing method to get a visual cue of how my simulation is working. I also used the animation to fine-tune the parameters — like friction, power, and collision coefficients — until I found one that was pretty similar to the pool table we ordered. Attached are pictures of what the animation looks like.
I will be spending my time this next week creating our greedy algorithm that chooses the best shot. I am currently on schedule and hope to be 100% done with implementing and testing this algorithm within 1-1.5 weeks so that we are ready to integrate and test MVP before carnival.