Valiant Technology Ltd

Feedback Form

INVESTIGATING CURVES

Chris Gregory, Senior Lecturer in Mathematics at Bradford and Ilkley Community College, continues his series of Geometry Microworld Part III.

In GO 11 we saw that the procedure POLY :NUM :SIDE can be used to draw not only any regular polygon we wish but also very good approximations to circles, and arcs of circles.

This procedure embodies the idea that a circle can be thought of as a regular polygon with a 'very large' number of sides - as the number of sides increases, the figure drawn becomes closer and closer to what we normally think of as a 'perfect' circular curve.

Can this idea be used to make the Turtle produce other kinds of curves?

Before we can take this notion very far, it will be useful to develop a further programming idea which will greatly increase the scope of what we can get the Turtle to do.

• Recursion:
The basic idea of recursion seems simple enough to grasp at first, although it has some hidden depths!

First of all, make the Turtle draw a circle, although this will be very slow. In order to walk along a circular path, we must take a step forward, turn a little, take another step forward, turn a little ------ and just keep on doing this - a rather tedious business!

A very simple procedure should do this:

TO CIRCLE
FD 1
RT 1
FD 1
RT 1
FD 1
RT 1
FD 1
RT 1
and so on

But this is going to be ridiculous - far too many stops will be needed to make a sensible procedure.

Try this instead:

TO CIRCLE
FD 1
RT 1
CIRCLE
END

The new idea here, that of recursion, is that the procedure calls itself, or rather calls another copy of itself. Probably the only way to get used to the idea is to act it out and see how it forces the same steps to be taken again and again.

When does the procedure end? Well, of course, it doesn't - we will have to press ESCAPE to stop it running when we decide we have had enough.

POLY again: We can now re-write the procedure POLY this time using the idea of recursion.

TO POLY :SIDE
FD :SIDE
RT 5
POLY :SIDE
END

Again, the procedure will not come to an end. How to put stop instructions into recursive procedures will be dealt with in a later issue.

We can now go a step further. So far, we have varied the size of each step (SIDE). We can also vary the size of the turn:

TO POLY :SIDE :TURN
FD :SIDE
RT :TURN
POLY :SIDE :TURN
END

Note that when the procedure calls a copy of itself, the copy must have the same number of variables as the original.

• Drawing a Spiral:
If we elaborate the procedure just a little bit more, the Turtle will draw another familiar curve - a spiral:

TO SPIRAL :SIDE :TURN
FD :SIDE
RT :TURN
SPIRAL :SIDE + 10 :TURN
END

• Investigation:
Experiment with this procedure and see what values seem to produce pleasing spirals - some surprising results are possible.

Instead of using '10' as the increment each time, investigate how varying this number affects the appearance of the spirals.


Back
  © 2004. Amethyst Consultancy Ltd.