Simple Circle Collision Detection

circle points Simple Circle Collision DetectionIf we know the Distance Formula the circle collision detection is pretty simple.

Lets start with the Point-Circle collision in the example.
Any point whose distance to the center of the circle is smaller than its radius is colliding with it, while any other point with a distance superior is not. Which according to the Distance Formula means:

if ( (Px – Cx)2 + (Py – Cy)2 <= r){
          // The point is colliding with the circle
}
else{
          // The point is not colliding with the circle
}

For Circle-Circle collisions the logic is the same, except you’re checking if the centers of both circles are further or not than the sum of both radius:

distance = √((C2x – C1x)2 + (C2y – C1y)2);
if ( distance <= r1 + r2){
          // The circles are colliding
}
else{
          // The circles are not colliding
}

You may also like...