MillionBalls
MillionBalls is a web-based simulator that improves your real-life pool game. While there is no real substitute for practice time at the pool table, there are times when you just can’t get to one.
Remember COVID-19? When the pool halls abruptly shot down like, this left a big void in my life because I’d been playing pool in leagues for years and a big part of my social and recreational life revolved around pool. This got me thinking about ways to continue to develop my skills and find ways to improve without access to a pool table.
The Ghost of an Idea
My initial idea was pretty simple. Show an image of a shot and predict if the aim was true and where the cue ball would go. That way I could continue training my eye to see shots correctly and keep improving my shotmaking ability even without access to a pool table.
I had never really done any 3D graphics at that point, but I was aware of WebGL. I figured that would a good way to get started quickly. A bit of research quickly led me to three.js.
Okay, this would be a quick little weekend project. All I need to do is draw a plane to represent the pool table, a few spheres to represent the balls, and I’ve have a little toy project to play with.
The Uncanny Valley of Pool
The first concept was easy enough, and did get it build pretty quicly. The initial version didn’t even draw a complete table… just a phantom target. It didn’t really simulate the motion of the balls, it just used Dr. Dave’s 30° rule to draw out the path of the balls.
I quickly discovered that this crude approximation was awful and unsatisfying. It turns out that poolplayer use cues from the table geometry, diamonds, shadows, etc. to build up a mental picture of a shot and the required angles. Our brain seems to be extremely sensitive to observing accelration and parabolic motion and things looked extremely unnatural when those effects were missing.
Down the Rabbit Hole
Okay, clearly a crude approximation wasn’t good enough. Time to break out the high school physics. I dusted off the parts of my brain where I had stored math concepts I hadn’t used in a couple of decades and got to work.
Fortunately, Dr. Dave’s book and website are treasure troves of information about pool physics and were great starting points.
At first glance, a billiards simulator is an intimidating thing. There are potentially 16 balls on the table in various states of motion. They could be sliding, rolling, spinning and interacting with each other as well as table elements like the cloth, cushions, and pockets.
Like other people before me, I quickly realized that the motion of balls on a pool table could be divided into distinct phases like sliding and rolling and the acceleration in each phase is constant to a high degree of precision.
For example, a sliding ballwill be decelearated by friction with the cloth while picking up angular velocity. This force disappears when loss of linear velocity and gain in angular velocity cause the ball to start rolling. At this point, the ball experiences a much smaller rolling resistance, which can also be modeled easily. Crucially, it’s possible to derive a closed-form expression for the position of ball as a function if time within each phase. That also makes it straightforward to predict the time a ball will collide with another object.
All I had to do was derive the equations of motion for each phase of motion,
predict the time each ball would collide with another object or change it
phase of motion, do some relatively straightforward math to calculate the
new velocities post-collision and repeat until all balls reach the STATIONARY
state.
The rest, as Neal Stephenson described in Cryptonomicon, is making license plates.
Making License Plates
As with so many other side-projects, I eagerly dived into the interesting parts of it. At some point the COVID pandemic eased, things reopened, and the project fell by the wayside as real pool and other social activities took precedence over simulated pool.
I was working on [Facteroid](https://vinaypai.com/projects/facteroid/ at the time and was having trouble getting enough sustained traffic to really make it work, and I decided it was time to put Facteroid on the backburner.
While looking for a full-time gig, I decided to take the time to do the few extra bits and pieces neede to turn the pool simulator from an experiement to a working web-based service, and MillionBalls was born.