Determining if two particles collide in a 2d container

51 Views Asked by At

I'm trying to determine if two particles collide within a certain period of time in a 2D container. Given the positions and velocities of the particles, I know a formula to determine if there is a collision between them in a 2D plane would be: $$t = \frac{y_2 - y_1}{v_{y_1} - v_{y_2}} = \frac{x_2 - x_1}{v_{x_1} - v_{x_2}}$$ Where if both equations are equal and greater than zero, there is a collision at time $t$.

This works in an infinite plane, but I'm not sure how to account for wall bounces when they are in a container. I tried considering the relative velocity, but that would assume the particle is travelling a direct path to its endpoint which doesn't work.

In my scenario, particles start at whole number coordinates and can only have integer value vectors for x and y. If they collide at all within a certain time, they both disappear, so there's no need to account for collision physics. Consider the points $(2,1)$ and $(3,0)$ with velocities in units/$s$ $(2,2)$ and $(4,4)$ respectively and a wall at $x = 4$. There should be a collision at $t=0.5s$.

I will also have to consider three particles and multiple collisions later. In this case I think I would just resolve the one with the lowest $t$ first, remove those particles and then reevaluate.