Project Folders
Teacher Resources
Student Resources
How Do I?
Site Map
Our Team

polygons 1 2 3 4 5 6 7 8 9
Polygons Expert 8
6 KB

Goal:   Draw a circle inside a polygon.


Vocabulary:   make, colorunder

Project Map

to polygon
t1, pu
t2, pu
setc whatcolor
setpensize howthick
repeat 1 + #sides [
t1, fd howbig
setpos t1's "pos
if touching? "t2 "t1 [pd]
t1, bk howbig rt 360 / #sides

to circle-in-a-polygon
make "count 0
t1, pu seth 0
rt 180 / #sides
repeat howbig [
fd 1
if colorunder = whatcolor [make "radius :count]
make "count :count + 1
bk howbig
setc circolor
setpensize 2
repeat 360 [
pu fd :radius rt 90
pd fd 1 bk 1 lt 90
pu bk :radius rt 1

to reset
ask [t1 t2] [home seth 0]


The challenge of this project is to find the proper radius for a circle to be inscribed in the polygon.   This means that the circle is drawn inside the polygon, just touching each side at the halfway point between two vertices.  

We use t1 as a "scout" - it points toward a side of the polygon (halfway between two vertices) then moves forward one pixel at a time with its pen up, checking until the color under it matches the setting on the whatcolor slider.   This means that the turtle has reached the side of the polygon.   As the turtle moves, it counts its steps.   When the color under it matches the color it is looking for, it sets the value of the variable radius to the number of steps it has travelled to that point.   This becomes the radius of the inscribed circle.

The turtle "scout" will keep travelling a bit farther until it has travelled the distance howbig, but this will not alter the value of radius.

  1. We can point turtle t1 to the midpoint of one side, where we wish the circle to touch, if the turtle turns half the number of degrees that it turns in the polygon procedure.   In the polygon procedure, we have been using the command rt 360 / #sides to turn turtle t1.   In the circle-in-a-polygon procedure, rt 180 / #sides turns turtle t1 half the number of degrees that it turns in the polygon procedure, since 180 is half of 360.  

  2. Make "count 0 defines a new variable called count and sets its initial value at 0.   The variable count will be used to count the number of steps t1 takes until it reaches the side of the polygon.   This value will become the radius of the inscribed circle.

  3. Make "count :count + 1 increases the value of count by 1 as t1 takes each step.

  4. if colorunder = whatcolor [make "radius :count] defines a new variable, radius, and sets it to the value of count at the point that t1 passes over the color matching the whatcolor slider.

  5. As turtle t1 draws a circle dot by dot, it uses the value of radius as the radius of the circle.   The inscribed circle should just touch the inside of the polygon at the midpoint of each side.  

What If?
Try different settings for howbig and howthick.

Can you use the value of radius in place of howbig to inscribe a smaller polygon inside the circle?

On Your Own - Project Ideas
Can you write a procedure that draws two circles: one circumscribing the outside of the polygon and one inscribing the inside of the polygon?

© copyright 2001 - 2016  OpenWorld Learning.   All rights reserved.