Calculate two circles bouncing off of each other

circlescollision detectiontrigonometry

I want to animate two circles bouncing off of each other, but for that I need to know how to calculate the new exit angle. It doesn't have to be physically perfect (but can be, if that might be easier), I would just like to do a simple animation.

I have:

  • Information about two circle's position, radius, speed and direction of movement (e.g. moving up would be 0° or 360°)
  • The calculation to know when two circles are colliding

Now I "only" need to know what the new angle of the circles is, when two collide. Problem is, I am not a mathematician, so if you could give me a straight-up formula (if that is even possible), I would really appreciate it.

Here I have drawn an example of what I mean:

enter image description here

Best Answer

I am quoting from this wiki page

The bolded variables in the following equation are two-dimensional vectors. These are: the position and velocity of particle 1 before collision: $\mathbf{x_1} $ and $\mathbf{v_1}$ and the position and velocity of particle 2 before the collision: $\mathbf{x_2} $ and $\mathbf{v_2}$. In addition the vector $\mathbf{v'_1} $ is the velocity of the first particle immediately after collision while $\mathbf{v'_2}$ is the velocity vector of the second particle immediately after collision.

The equations are:

First define the unit normal vector $\mathbf{n} = \dfrac{\mathbf{x_1} - \mathbf{x_2} }{ \left| \mathbf{x_1} - \mathbf{x_2} \right|}$

$\mathbf{v'_1} = \mathbf{v_1} - \dfrac{2 m_2}{m_1+m_2} (\mathbf{n} \cdot (\mathbf{v_1}-\mathbf{v_2}) ) \mathbf{n} $

and

$\mathbf{v'_2} = \mathbf{v_2} - \dfrac{2 m_1}{m_1+m_2} (\mathbf{n} \cdot (\mathbf{v_2}-\mathbf{v_1}) ) \mathbf{n} $

If we assume that $m_1 = m_2$ (equal masses) then the equations simplify to:

$\mathbf{v'_1} = \mathbf{v_1} - (\mathbf{n} \cdot (\mathbf{v_1}-\mathbf{v_2}) ) \mathbf{n} $

and

$\mathbf{v'_2} = \mathbf{v_2} - (\mathbf{n} \cdot (\mathbf{v_2}-\mathbf{v_1}) ) \mathbf{n} $

As an example, suppose both circles have the same radius and the same mass, and that the first circle is moving with its center position as function of time given by:

$\mathbf{x_1}(t) = (0, -10) + (1, 2) t $

it follows that

$\mathbf{v_1} = (1, 2)$

and suppose that the center of the second circle is given by

$\mathbf{x_2} = (-10, 0) + (2, 1) t $

it follows that

$\mathbf{v_2} = (2, 1) $

We want to calculate the value of $t$ at which the two circles will collide. Suppose the radius of each of the circles is $1$. Then we want the distance between the centers to be $2$.

We have

$\begin{equation} \begin{split} \left| \mathbf{x_1}(t) - \mathbf{x_2}(t) \right| &= \left|(10, -10) + t ( -1, 1 ) \right |\\ &= \sqrt{ 200 - 40 t + 2 t^2 } = 2 \end{split} \end{equation}$

Its solution is $t = 10 \pm \sqrt{2} $

So we'll select $t = 10 - \sqrt{2} $ (the first time after $t = 0$ )

So, at the collision , we have

$\mathbf{x_1} = (0, -10) + (10 - \sqrt{2}) (1, 2) = (10 -\sqrt{2} , 10 - 2 \sqrt{2} ) $

$\mathbf{x_2} = (-10, 0) + (10 - \sqrt{2}) (2, 1) = (10 - 2 \sqrt{2}, 10 - \sqrt{2} )$

Hence the normal vector $\mathbf{n}$ is given by

$\mathbf{n} = \dfrac{1}{\sqrt{2}} (1, -1) $

Substituting all this into the equations, we obtain,

$\begin{equation} \begin{split} \mathbf{v'_1} &= (1, 2) - \dfrac{1}{2}( (1, -1)\cdot(1-2, 2 - 1) ) (1, -1) \\ &= (1, 2) + (1 , -1) = (2, 1) \\ \end{split} \end{equation}$

Similarly, one can obtain that $\mathbf{v'_2} = (1, 2)$