# Energy Conservation – How to Get the New Direction of 2 Disks Colliding

collisionconservation-lawsenergy-conservationmomentumsimulations

I'm developing a 2D game including collisions between many disks. I would like to know how I can get the angle corresponding to the new direction of each disk.
For every disk I have this information : direction (integer), speed (float), and position ($x$;$y$, which are both integers).

Of course I know that the new direction will be the opposite of where the collision happens (disk hit on the bottom-left will go to the top-right), but I don't know how to calculate exactly the new angle.

In the ideal case where the collision is instantaneous and there is only a single point of contact, the forces experienced by each object can only be along the line that connects the centers and passes through the contact point. Actually, the "force" will be infinite, but it will impart a finite impulse (i.e. change in momentum) during the infinitesimal interval of time during which the collision occurs. There can be no component of impulse orthogonal to this, because that would amount to a "force" tangential to the circle. With any finite coefficient of friction, you cannot affect a circle by pushing tangent to it at just a point.

This constraint, together with conservation of momentum in two directions and conservation of energy, is enough to determine the motion of both circles given any initial conditions (which needs 4 scalars to be defined fully).

If the target circle is sitting still before the collision, its direction of motion afterward is easy enough to find: It is exactly along the line connecting the two circles' centers at the moment of contact. (Make sure you go the right way along this line - only one of the directions is sensible.) The new direction of the circle that was originally moving will simply be given by the direction of the vector sum of its old momentum and the momentum imparted to it in the collision. If you want numbers, say the moving circle makes contact when its center is at $(x_1, y_1)$, and the other center is at $(x_2, y_2)$. Then the angle at which 2 moves away from the collision is $$\theta = \frac{180^\circ}{\pi} \tan^{-1}\left(\frac{y_2-y_1}{x_2-x_1}\right).$$ By the way, it might be easier to just use $x$ and $y$ components of velocity, rather than speeds and angles.

Of course, if you want to take this to the next level of realism, you may need to account for the following effects:

• Kinetic energy is lost (perhaps by a certain percentage) with each collision.
• The collision could result in torques, transferring angular momentum.
• Spinning objects may curve while sliding. This is a complicated effect though, and you probably have to model it with a kinetic coefficient of friction that varies with velocity.

Finally, for numerical accuracy, I suggest keeping all numbers as floats in the calculations and only rounding to the nearest integers when rendering.