Particle Collision

From programming_contest
Jump to navigation Jump to search

This problem asks us to simulate defined interactions between three particles. It is not algorithmically challenging, but implementationally "annoying".

We can first check whether 1 will hit any particle. We can use the point-line distance formula to check the closest approach of 1 to 2 or 3. If it is >2r for both, then there is no collision.

Assuming there is a collision, we must determine the time it occurs. This can be done either by binary searching for the time when the balls are exactly 2r apart, or directly, using knowledge of the distance between the point and the line formed by 1, the time when we make the earliest pass, and a hypotenuse of 2r, and a little bit of trig. We evaluate the collision which occurs earliest.

When a collision occurs, we can calculate the equation that the new ball moves in. The direction the new ball moves in will be the ray formed from the first particle at the time of contact, through the center of the second particle.

We repeat the process to see if the other particles collide.