Approximating the Circle

Drawing Circles the Hard Way – with Straight Lines

Our turtle has a local viewpoint. He can draw a line one unit, turn one degree, then repeat that 360 times, coming back around where he started, but at no time is a center or radius known, even though the approximate circle has both. By measuring the drawn approximate circle or by doing a little math the radius can be found. The circumference is total direction traveled. Using the formula Circum = pi*(Dia) and substituting 360 for the Circum the radius is found to be 180 / pi or approx 57.3. If we make the subroutine more general to accept as input the angle turned between each line and the length of the lines, we no longer have a loop of 360 and we need to calculate the number of lines to draw.

num_lines = 360 / angle

will give a full circle (as long as angle is a multiple of 360). With this sub we can experiment with varying angles and line lengths and see how the radius changes. Using 1 and 1 gives the same results as before, but also using any two numbers that are the same, such as 10 and 10, give a circle (more or less) with the same radius as 1 and 1. Using different numbers for angle and line length will make the circle diameter change as a direct proportion of the ratio

len_lines / ang.

Longer lines will give larger diameters. Larger angles will give smaller diameters.   We can see by experimentation that every ratio of line_length to angle has a definite radius, so lets find that equation.
We already needed an equation between num_lines and ang, which was num_lines = 360 / ang. If for instance we turned 120 degrees with each turn, we would only need 3 lines and our approximate circle would be a triangle. If we turn one degree, we need 360 lines.

We also used the fact that 360 lines of one unit had a circumference of 360. No matter how many lines of whatever length,
the circumference is num_lines * len_lines.

C= (num_lines) * (len_lines) and into that we substitute our calculation num_lines = 360 / ang.

C = (360 / ang) * (len_lines)

Circumference of course is 2 pi R
2 pi R = (360/ang) * len_lines
R = (180/ang) * (len_lines/pi)

R = (180/pi) * (len_lines/ang)

and there is our ratio of line length to ang as a direct proportion to R.

Don’t forget, like I did when measuring the radius of a polygon, this radius is calculated by adding the straight line lengths and calculating the radius of a circle of that circumference. If the straight line approximation is crude, the radius will be crude. The more lines used to approximate the circle, the better the radius calculated from them.

R and ang can be switched with a little algebra to find ang.

ang = (180 / pi) * ( len_lines / R)

and now we can re-write our sub-routine so it accepts the radius and len_lines as argument and calculates the angle to turn each line and the number of lines to close (or almost close) the circle. Finally having written a general program to draw circles of a given radius using straight lines of a given length, drawing an arc of given degree is just reducing the number of lines drawn by the same ratio as arc degrees to 360.

for a circle
num_lines = 360 / ang

for an arc with deg as the new input
num_lines = 360 / ang
num_lines = (deg / 360) * num_lines

but more simply this is
num_lines = deg / ang 