ekiefl / pooltool

A sandbox billiards game that emphasizes realistic physics
https://pooltool.readthedocs.io
Apache License 2.0
226 stars 35 forks source link

Notebook for validating 30 degree rule #119

Closed zhaodong-wang closed 7 months ago

zhaodong-wang commented 7 months ago

This notebook tried to reproduce the 30-degree rule and got pretty good results, although still a bit different comparing with what Bob Jewett had (probably based on measurements).

newplot

ekiefl commented 7 months ago

Hi @zhaodong-wang I made some cosmetic changes and some functional changes.

I like the use of a jupyter notebook, but I find it hard to track changes. I converted things to a .py file simply because I thought it would be easier for you to see the changes I made by observing the individual commits.

Besides cosmetic changes, there were two major things I modified.

First, their analysis demands that the incoming cue ball state is rolling. Using the default physics model for the cue-stick model, the cue ball enters the rolling state upon impact (or nearly upon impact) when the parameter b is set to 0.8. I set this as the default and wrote an assertion that explicitly verifies that the cue ball is rolling prior to impact.

This leads to a velocity dependent result:

image

Second, the correct equation for fullness is $F(\theta) = 1 - \sin(\theta)$. After applying the appropriate change, we reproduce their result:

image

Here is the range between a 1/4 ball hit and a 3/4 ball hit, which matches their range of output angles they calculated (27 to 34 degrees):

image

zhaodong-wang commented 7 months ago

Hi @ekiefl thank you for reviewing the code and making these changes! The fullness was indeed a mistake, I didn't think carefully (only thought about two endpoints 0 deg ->1, 90 deg -> 0, lol). And just by making this one change the shape of the curve is already pretty close.

I thought about the rolling part but didn't try to see what would happen if we forced the white ball to be rolling (b=0.8). This is a very interesting finding I think: "The deflection angle is irrelevant to the ball speed, as long as the cue ball is rolling". And I think ensuring the cue ball in the rolling state is critical, because considering a limiting situation where the speed is very high, then it would be a stun shot (no rolling has been developed at all) and the deflection angle will be 90 degrees. Any state in between (mixed rolling and sliding) would result in some degree between ~30 - 90, and it will increase as the speed increases, which kind of explained the results that I had previously.

Another thing I want to point out is that (maybe you already know), the deflection angle is the difference between the initial cue ball direction, and the direction when the cue ball is eventually rolling, not the direction connecting the contact point and the cue ball location. The cue ball will initially go towards the tangent line and then curve to the eventual direction, the distance depends on the speed. In real-world situations, instead of this simulated 100m x 100m table, before the cue ball eventually rolls, it might have already hit the cushion, so it still requires experience to judge how far the cue ball will curve to estimate the cue ball path.

Overall, it is great that we precisely reproduced the results they have, making me curious if they used the same physics formulas to generate that diagram.

I can remove the notebook file and only keep your .py file. The reason I used jupyter notebook is the plotting can be pretty interactive. Maybe we can create another folder putting notebooks? These can be the interactive demos of pooltool.

ekiefl commented 7 months ago

Another thing I want to point out is that (maybe you already know), the deflection angle is the difference between the initial cue ball direction, and the direction when the cue ball is eventually rolling, not the direction connecting the contact point and the cue ball location. The cue ball will initially go towards the tangent line and then curve to the eventual direction, the distance depends on the speed. In real-world situations, instead of this simulated 100m x 100m table, before the cue ball eventually rolls, it might have already hit the cushion, so it still requires experience to judge how far the cue ball will curve to estimate the cue ball path.

Exactly! Here is a plot of rolling trajectories, with the same cut angle, but different speeds:

image

Harder shots follow the tangent line for longer, but they all converge to the same outgoing angle.

Overall, it is great that we precisely reproduced the results they have, making me curious if they used the same physics formulas to generate that diagram.

I'm pretty sure they are using the exact some physics.

Overall, this was a pretty demonstrative effort. Thanks for spearheading it. I will make some final touchups tomorrow and approve the PR for merging. Feel free to merge it once I've done that.

Maybe we can create another folder putting notebooks? These can be the interactive demos of pooltool.

Since the sandbox is just for experimentation, I think we can keep notebooks in there alongside .py files. I transformed it to a python file because my IDE doesn't support .ipynb, but I think there are advantages to keeping it as a notebook. Feel free to convert the .py back to a .ipynb if you want.

ekiefl commented 7 months ago

Congrats on becoming a collaborator of the project 🍾

If you want to turn it back into a notebook, feel free to open another PR.