Circle-to-circle collision detection is a fundamental topic in computer graphics, game development, and physics simulations. Unlike the intricate math required for detecting collisions between irregular polygons or complex 3D shapes, circle-to-circle collision detection is refreshingly straightforward. It leverages the inherent symmetry of circles to provide an efficient and easy-to-implement solution.

In essence, if you have two circles, each defined by a center point and a radius, determining whether they collide is a matter of a simple geometric calculation. All you need to do is compare the distance between the two centers to the sum of their radii. If the distance is less than or equal to the sum of their radii, a collision is occurring. This ease of calculation makes circle-to-circle collision detection a popular choice in scenarios where quick and frequent collision checks are required.

$\text{Collision} = \begin{cases} \text{True}, & \text{if } D := \sqrt{(x_1 - x_2)^2 + (y_1 - y_2)^2} \leq r_1 + r_2, \\ \text{False}, & \text{otherwise}.\end{cases}$

where $$\mathbf{c}_1 = \begin{bmatrix}x_1 & y_1 \end{bmatrix}^T$$ and $$\mathbf{c}_2 = \begin{bmatrix}x_2 & y_2 \end{bmatrix}^T$$ are the coordinates of the centers of each circle.

Upon detecting a collision between two circles, we separate them according to their overlap. To find the overlap distance $$P$$ (see image above), subtract the distance between the circle centers from $$r_1 + r_2$$. To determine the direction in which to move $$C_2$$ away from $$C_1$$, multiply $$P$$ by the normalized vector $$\vec{C}_{12}$$ and divide by 2. Use the other half of $$P$$ to move $$C_1$$ along $$-\vec{C}_{12}$$.
As you can see, inside this method I've added also two statements that check if one of the two bodies is static. In this case, you don't need to move the static object by the MTV (minimum translation vector, defined as $$\vec{v}_{mtv} = \vec{n} \cdot d_{depth}$$). Important to note, that this method is only responsible for removing the overlap between the two bodies (this method works for all kinds of bodies not only circles). We discuss the impulse calculation later in Part VI.