It's not important for National Curriculum Computing at KS3 that you understand how to create a program to draw a circle, but, if you're interested, here are two techniques explained. GCSE Maths now includes trigonometry and Pythagoras in both tiers, so these techniques should be suitable for students of GCSE Computer Science.
GCSE Maths students will have been introduced to trigonometry - sines and cosines - for their Maths exam. If you don't know what sines and cosines are, or you would like a reminder of what they are, check out the animation here.
This method of drawing a circle works by varying the angle n and using trigonometry to work out where the point (x,y) would be for that angle. As you could hopefully see from the animation, for a circle of radius 1, x would be cos(n) and y would be sin(n). For a larger circle, you just need to multiply by the radius. The program draws a circle of radius 400, so the x-coordinate is 400 x cos(n), and the y-coordinate is 400 x sin(n).
There is, however, one slight complication. Unlike your calculator, most programming languages (and applications such as Excel) measure angles in radians, rather than degrees. The program therefore uses the RAD() function to convert the angle from degrees to radians before calculating the sine or cosine.
You might find the Maths for this method more straightforward - and so does the computer! Square roots are quicker for the computer to calculate than sines and cosines, which explains why this method is quicker.
Pythagoras works with right-angled triangles. Imagine a triangle with one corner in the centre of the circle, and another on the circumference. The hypotenuse (the longest side) will always be equal in length to the radius.
This method of drawing the circle varies the x-position. From the x-position, we know the width of the triangle, and we know the length of the hypotenuse, so we can use Pythagoras to work out the height of the triangle to give us the y-position.
If we assume that (0, 0) is in the middle of the circle, then the value of x is the width of the triangle - it might be negative, but as we're going to square it, it doesn't matter. If the hypotenuse is 400, then y2 = 4002 - x2, or y is the square root of (160000 - x2).
If you would like to see how these techniques work in practice, watch the
programming efficiency on the
AdvancedICT YouTube channel.