Calculate x/y point that 2 moving balls will collide
Drawing of @dmckee's answer
Edit
Just in response to @ArtB necromancer's answer, the solutions for point D in the above graph could be written:
1/2 {(Ax+Bx+2 d Dx Cos[alpha]- Dx Cos[2 alpha]+ 2 Dy (Cos[alpha]-d) Sin[alpha]),
(Ay+By+2 d Dy Cos[alpha]- Dy Cos[2 alpha]- 2 Dx (Cos[alpha]-d) Sin[alpha])
}
Where
Dx = Ax - Bx
Dy = Ay - By
And
d = Sqrt[4 r^2 - (Dx^2 + Dy^2) Sin[alpha]^2]/Sqrt[Dx^2 + Dy^2]
HTH!
Some things to take note of:
- When two balls, each of radius
r
collide their centers are2r
apart. - Your first ball can be assumed to travel in a straight line (well, first approximation, but start with this), and you can find the angle,
alpha
between this path and the direction from the first ball to the second. - You know the center of the stationary ball, no?
Now you have some geometry to do.
Do this construction:
- Mark the current center of the first (moving) ball as point
A
. - Mark the center of the stationary ball as point
B
. - Construct line segment
AB
. - Construct the ray,
R
, fromA
in the direction of movement. - Construct a circle of radius
2r
aroundB
. - Drop a segment from
B
perpendicular toR
call the point of intersectionC
. - You know the distance
AB
and you can find the anglealpha
betweenAB
andR
, with the Law of Sines find the length ofBC
. - From that length determine if there are 0, 1 or 2 solutions. If there are 0 or 1 you are done.
- Construct point
D
where the circle meetsR
closer to A, and use the Law of Sines again to find the distance AD. - The point of collision is the midpoint of
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.