I'm trying to make what is (essentially) a simple pool game, and would like to be able to predict where a shot will go once it hits another ball.
The first part is, I believe, to calculate if the cueball will hit anything, and if it does, where it collides. I can work out collision points for a line and a ball, but not 2 balls.
So given the x/y positions and velocities of 2 balls, how do I calculate the point at which they collide?
(PS: Im aware I can do this by calculating the distance between the two balls every step along the way, but I was hoping for something a little more elegant and optimal.)
Example of setup: trying to calculate the red dot
Some things to take note of:
r
collide their centers are 2r
apart.alpha
between this path and the direction from the first ball to the second.Now you have some geometry to do.
Do this construction:
A
.B
.AB
.R
, from A
in the direction of movement.2r
around B
.B
perpendicular to R
call the point of intersection C
.AB
and you can find the angle alpha
between AB
and R
, with the Law of Sines find the length of BC
.D
where the circle meets R
closer to A, and use the Law of Sines again to find the distance AD.BD
and now you know everything.
Constructing efficient code from this is left as an exercise.
BTW-- This construction won't work if both balls are moving, but you can transform into a frame where one is stationary, solve it that way, then transform back. Just be sure to check that the solution is in the allowed area after the reverse transformation...
/ Physicists can't not make comments like this. I tried to resist. I really did.