This method is also checking to see if two shapes intersect with each other, but as the title suggests, it does so using circles. There are advantages and disadvantages compared to other methods.

Skill level 1

## Projects related to or that demonstrate these concepts

• None yet The radius overlap method works well with shapes more circular in nature and less well with elongated shapes as shown in the image above. From the previous image, it is easy to see how the radius overlapping method is inaccurate for these particular objects and not hard to imagine how for a circular object, like a ball, it would be perfect.

Here is some pseudo code to show how we can implement this method. The code assumes that the ship and enemy objects have initialized centerX, centerY and radius member variables. It also assumes that distanceX, distanceY have been declared as an appropriate type, possibly float or similar.

Actually the Java, static Math.sqrt method takes and returns a value of type double.

The code below doesn’t mention the types as they will vary depending upon your platform and requirements.

```// Get the distance of the two objects from
// the edges of the circles on the x axis

distanceX = (ship.centerX + ship.radius) -

// Get the distance of the two objects from
// the edges of the circles on the y axis
distanceY = (ship.centerY + ship.radius) -

// Calculate the distance between the center of each circle
// Math.sqrt is from Java. All modern languages have an equivalent
distance = Math.sqrt(distanceX * distanceX + distanceY * distanceY);

// Finally see if the two circles overlap
```Math.sqrt(distanceX * distanceX + distanceY * distanceY);