## Thursday, July 31, 2014

### Drawing Polygons using Pro-Bot

In this programming assignment, we shall draw polygons using Pro-Bot. We shall start by using sequential programming to draw the polygons. Next, we shall look at some regular polygons and learn how to use Pro-Bot’s Repeat Loops to draw them. We shall also develop a generalized algorithm to draw regular polygons using Pro-Bot. We can store programs for the polygons as Procedures on Pro-Bot.

Computer Science concepts involved:  Sequential programming, Repeat loops, Algorithm development

Math concepts involved:  Polygons (regular and irregular), Linear & Angular Measurements, Interior angles, Supplementary angles

Hours required:  3 or more

### Polygons

In geometry, a polygon refers to a closed, two-dimensional figure formed by a set of straight line segments. The straight line segments are called the polygon’s edges or sides, and the points where two edges meet are the polygon's vertices or corners.

We see polygons of different types all around us in our daily lives. Here is an interesting article that I found on mathforum.org, as to where we see different types of polygons in our daily lives.

If all edges are equal and all angles are equal, then it is a regular polygon. Else, it is an irregular polygon.

Square:

Use Pro-Bot to draw a square of sides 8 cm. Each interior angle is 90 degrees.

Rectangle:

Use Pro-Bot to draw a rectangle of sides 4 cm and 6 cm. Each interior angle is 90 degrees.

Parallelogram:

Use Pro-Bot to draw a parallelogram of sides 4 cm and 6 cm. One pair of interior opposite angles is 45 degrees each and the other pair is 135 degrees each.

Note: Remember that for a parallelogram, opposite angles are equal.

In the figure of the parallelogram above, angles marked ‘a’ are equal; they are opposite angles. Similarly, angles marked ‘b’ are equal; they too are opposite angles. The angles ‘a’ and ‘b’ add up to 180 degrees; ‘a’ and ‘b’ are supplementary angles.

Note: Remember that when Pro-Bot has to draw a 45 degree interior vertex, it would have to turn 135 degrees and not 45 degrees, assuming it was moving in the forward direction before making the turn. Similarly for the 135 degree vertex, Pro-Bot would have to turn 45 degrees. Can you see why?

Rhombus:

Use Pro-Bot to draw a rhombus of sides 6 cm. One pair of opposite interior angles is 60 degrees each and the other pair is 120 degrees each.

Next, use Pro-Bot to draw a rhombus of sides 6 cm. One pair of opposite interior angles is 90 degrees each. What shape do you get?

Equilateral Triangle:

Use Pro-Bot to draw an equilateral triangle of sides 6 cm. Each interior angle is 60 degrees.

Note: Remember that when you draw an equilateral triangle using Pro-Bot, at each vertex Pro-Bot has to turn 120 degrees (supplementary angle), and not 60 degrees, assuming it was moving in the forward direction before making the turn. Can you see why?

Right Triangle:

Use Pro-Bot to draw a right triangle of sides 3 cm, 4 cm and 5 cm. The interior angle between the 4 cm and 5 cm sides is 36 degrees. The interior angle between the 3 cm and 5 cm sides is 54 degrees. The interior angle between the 3 cm and 4 cm sides is 90 degrees.

Note: Remember that when you draw a right triangle using Pro-Bot, at each vertex Pro-Bot has to turn at its supplementary angle, and not the interior angle, assuming it was moving in the forward direction before making the turn.

### Drawing Regular Polygons using Repeat Loops in Pro-Bot

For the various shapes above that you drew using ProBot, you could see that in the case of programs for for the regular polygons (polygons with equal sides and equal interior angles), there is a pattern of instructions that keeps repeating multiple times.

You can rewrite your programs for the square and the equilateral triangle using Repeat Loops in Pro-Bot.

Use Pro-Bot to draw each of the shapes below. Use Repeat Loops to write your programs.
1. Equilateral Triangle:   Use Pro-Bot to draw an equilateral triangle of sides 6 cm. Each interior angle is 60 degrees.
2. Square:    Use Pro-Bot to draw a square of sides 6 cm. Each interior angle is 90 degrees.
3. Pentagon:   Use Pro-Bot to draw a pentagon of sides 6 cm. Each interior angle is 108 degrees.
4. Hexagon:    Use Pro-Bot to draw a hexagon of sides 6 cm. Each interior angle is 120 degrees.
5. Octagon:    Use Pro-Bot to draw a octagon of sides 6 cm. Each interior angle is 135 degrees.
6. Nonagon:   Use Pro-Bot to draw a nonagon of sides 6 cm. Each interior angle is 140 degrees.
7. Decagon:   Use Pro-Bot to draw a decagon of sides 6 cm. Each interior angle is 144 degrees.

After drawing the various polygons, ask the students to identify a few examples of where they might see these shapes in their daily lives. For example: a sandwich cut in half is a triangle, roof trusses are triangles, a STOP sign is an octagon, a YIELD sign is a triangle, cells in beehives/ honeycombs are hexagons, etc.

Here is a set of solutions for this assignment.

### Develop an Algorithm for drawing Regular Polygons using Pro-Bot

Now that you have written programs for Pro-Bot to draw various regular polygons, let us develop a generalized algorithm for the same.

1. Is it more efficient to use Repeat Loops or Sequential Programming when you write programs for regular polygons on Pro-Bot?
2. From your programs above, can you identify a technique to find the angle at which Pro-Bot should turn at each vertex for a regular polygon?
3. Given the length of a side of a regular polygon and the angle you found using your above technique, can you write a program for drawing a regular polygon of N sides (N being any whole number) using Pro-Bot?
4. Can you now generalize your method and write down the various steps involved, as an algorithm.

### Experiment more with Regular Polygons using Pro-Bot:

1. While developing your algorithm, did you notice that as the number of sides of the polygon increases, the shape of the polygon tends to a circle? What happens to the interior angle of the polygon in this case; does it increase or decrease?
2. What happens to the angle at which Pro-Bot has to turn as the number of sides of the polygon increases? Does it increase or decrease?
3. What is the smallest measurement of angle that you can use on Pro-Bot? What is the smallest length that you can draw using Pro-Bot?
4. Using the algorithm that you developed above for Pro-Bot, draw a regular polygon using that uses the smallest angle and the smallest length that Pro-Bot can provide as its dimensions. What shape do you get?
5. Draw a regular polygon using Pro-Bot, just like the one in the previous question, that uses the smallest degree of angle, but with the length of the side increased by 1 unit. What shape do you get?
6. What happens to the shape if you keep increasing the length of the side by 1 unit at a time, but keep the angle constant at the smallest value?
7. What happens if you increase both the length and the angle by 1 unit each time? What difference do you see?

### Challenge Question:

1. Can you write a program for Pro-Bot to draw a circular maze (a spiral shape) using all of the ideas that you learned from the above questions? It is easier to start the spiral from inside and start moving outwards. Start the spiral with the smallest length and angle that Pro-Bot can provide and then build outwards.