Quick Collision Check

This is one of the most useful tricks I have encountered for collision detection. I will be working in 2 dimensions in this example but it is easily extended to 3 dimensions. If you are programming a game, you will more than likely at some point need to implement some collision detection code. The simplest way to check if two objects are colliding with each other is to wrap them in what is called a bounding circle (or sphere if working in 3 dimensions). Every circle has a center point and a radius. To see if two circles overlap (collide) with each other you take their center points and subtract them from each other. We will call this value the distance squared. Next we take the radius for each circle, square it, and add them together. If the distance squared is less than the sum of the two squared radii, then you know they are penetrating. How sweet is that?

Here is a picture to make it more clear:

2 circles

The red lines represent the length of the radius of the circle. The blue line represents the distance between the two center points of the circle. From this picture, you can clearly see that the two circles do not overlap and do not penetrate one another.

Here is some pseudo code:
bool checkBoundingCircles(Circle circle1, Circle circle2)
     float totalRadius = circle1.radius + circle2.radius;
     vector2D distanceSquared = (circle1.position - circle2.position).lengthSquared();
     if ((totalRadius * totalRadius) >= distanceSquared )
          return true;
     return false;
Back to Main Page