# PHP Challenge 7 - Going Round in Circles

In this challenge you are required to let the user enter the coordinates of the centre of two circles and their respective radii.

You then have to calculate if the circles:

- touch
- do not touch
- overlap

If we consider some simple examples then we could have the following:

For example:

- Circle A has coordinates (1, 2) and a radius of 2
- Circle B has coordinates (-1, -3) and a radius of 3

If we were to sketch this then we would have:

In this case we can cearly see that the 2 circles do not touch.

## HINTS

This challenge involves the use of some mathematics. You will need to apply Pythagoras' Theorem.

You will need to calculate the distance between the centres of the 2 circles. In our example case we have the following:

What considerations will you need to give if the centres of the circles are vertically or horizontally opposite each other?

What tests will you need to make on the user inputs?

## SAMPLES TO TRY

CIRCLE A | CIRCLE B | ||||
---|---|---|---|---|---|

CASE | COORDINATES | RADIUS | COORDINATES | RADIUS | RESULT |

1 | (2, 3) | 2 | (5, 7) | 3 | The circles touch |

2 | (-1, 0) | 1 | (5, 0) | 4 | The circles do not touch |

3 | (-4, 7) | 10 | (1, -5) | 5 | The circles overlap |

## Would you like the solution to this challenge?

The full video solution together with downloadable code is available in the PHP for Beginners course.

This course is taught by Patrick Morrow, a national award-winning teacher, who is very active in the course and who provides full support.

For more information click here.

## Comments

Your email address will not be published.

### PHP for Beginners

### PHP, MySQL and PDO

Coming soon, a full course on using PHP, MySQL and PDO. Be notified as soon as the course goes live.

An interesting challenge. There is a lot more to it than you first think!

by Edwin, 11-Jan-2016

Yes, this is an interesting challenge. Few students manage to consider all possibilities.

by Patrick Morrow, 14-Jan-2016