Pages

21.1.08

LOGO Routines: Building Polygons

In my search log on Feedburner today I had an interesting search request, "probot hexagon instructions." I am assuming that this was from someone seeking help in writing or inputting a routine for the floor turtle that will generate a hexagon.

Creating a regular polygon with the Probot is similar to doing so with LOGO, though the tool has its own programming quirks. This post is intended to be a generic response to help with a variety of tools and I hope it pays off. To draw shapes, commands can be input to such devices either by repeatedly inputting a turn size followed by a distance (this represents a side length), or by creating a repeat [procedure].

Turns are measured in degrees, and the size of the turn inputted depends on the number of sides and turns you want the turtle to make in drawing the shape. On completion of the shape, the turtle will make one full turn of 360 degrees, so the size of the turn each time will be 360 degrees divided by the number of turns.

Lets reason for a minute and say I wanted to draw a square. What do I know about the properties of a square. Well it is a regular shape, it has 4 equal sides and 4 equal angles. To draw the shape my turtle will need to travel along the shape's perimeter, turning 4 times, after traveling the same distance between each turn. Since a square is regular every turn, angle or corner will need to be the same size.

By the time the turtle has finished its journey around the square it will have made one complete turn or rotation. A full turn is 360 degrees. each turn must be 360 divided by 4, every turn inputted will need to be 90 degrees, if each turn is to be equal.

Since my square is a regular quadrilateral all forward distances will also need to be the same, as all sides are the same length.

To make my square then I might input each step individually

fd 50 rt 90, fd 50 rt 90, fd 50 rt 90, fd 50 rt 90

pressing go or enter in between each step

or since I want to go fd 50 rt 90 four times, I could use a rpt command and enter a procedure like this

Using the Probot

Rpt 4 [
Fd 50
Rt 90
]
End

In LOGO

To Square
Rpt 4 [ Fd 50 Rt 90]
End

before pressing enter or go. End tells my turtle, that once it has done everything in the brackets 4 times I want it to stop.

Usually I need to name a procedure like this, so I might call this one square.

Changing Shape

Within a procedure if I want to change the shape I make, I need to change the size of the turn.

In order to calculate the turn size, I need to know how many turns the turtle will eventually make to complete the shape, and then to divide this by the size of a full turn ie 360.

LOGO and use of the floor turtle is a fantastic context in which to set investigations and multistep problem solving involving the properties of shape.

Equilateral Triangles need 3 turns of 120 or 360/3
Regular Pentagons 5 turns of 72 or 360/5
A Regular Hexagon 6 turns of ? or 360/?

Challenge:

Can you calculate the turn sizes necessary to create all of the regular polygons with angles totaling 4 to 10. (ie squares to decagons)

Insert a pen to the probot or floor turtle, or in LOGO ensure you have typed pd, or pendown before you begin

Test your predictions by substituting your turn and repeat values in your procedures?

Make and then save procedures for each shape by name, and test these do they still make the shapes you predicted?

What happens if.. I repeat 6 [hexagon rt 60] end
What happens if.. I repeat 10 [hexagon rt 36] end

Can you find other pairs of numbers, that when multiplied together make 360, try substituting these in the routine, for the repeat and turn numbers, what happens?

These activities should work equally well with floor turtles and a variety of on screen LOGO based environments, though be warned each tool and environment will have its quirks so be prepared to play with the kit first, to ensure you are familiar with these. I hope this is helpful.

Want to play with onscreen control at home, why not try MSW LOGO, a personal favourite freeware download for educational use from softronix. The processes and procedures can be practiced here and then adapted to work with other tools. There are also some really helpful guides hidden behind the scenes on the website so check these out too.

2 comments:

Anonymous said...

To differentiate for the top stream it should be possible to teach the concept of parameter substition so the challenge would be to write a procedure called Polygon which draws one of any number of sides depending on the number passed across. Most class teachers will stop before getting to this stage, which is a shame because for those who 'get it' a whole new world of constructionism opens up.

Two Whizzy said...

Thanks Andy