CODING ACADEMY

View Original

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

See this content in the original post

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.

To enrol in the course click here.