[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

LOGO-L> Is the "spiral" thread "poly" in disguise?



Anyone else notice what has happened with the spiral subject?

It's "poly" all over again although some of us switched seats :-)

Note that in the functions below I hard coded the radius or the
rate at which spiral expands. This of course can be a parameter
in any of these functions and has no influence on the point I'm
trying to make here. Look at the similarities that evolved.

One set of solutions is like the original "poly" solution.

to circle1
repeat 360 [fd 1 rt 1]
end

to spiral1
repeat 1000 [fd repcount/100 rt 5]
end

Another set of solutions is like the original "arc" solution (uses trig)

to circle2
pu
repeat 360 [setxy 100*cos repcount 100*sin repcount pd]
end

to spiral2
repeat 720 [setxy repcount/10*cos repcount repcount/10*sin repcount]
end

Another set of solutions is like "ARC" but letting Logo do the trig
(i.e. working in polar coordinates). This is like Brian's old "Circle"
function or Yehuda's newest Spiral function.

to dot
setpixel 0
end

to circle3
pu
repeat 72 [fd 100 dot bk 100 rt 5]
pd
end

to spiral3
pu
repeat 720 [fd repcount/10 dot bk repcount/10 rt 5]
pd
end

The last 4 functions above can be written as functions of x where x is an
angle. This is simply an example of keeping the functions logically separate
from the drawing. You'll notice I can mix and match any drawing routine
(dots or connected_dots) with any function.

to circle2_of_x :x
   output list 100 * cos :x ~
               100 * sin :x
end

to spiral2_of_x :x
   output list :x/10 * cos :x ~
               :x/10 * sin :x
end

These look ugly but they require no trig knowledge and they have
no side effects and can be used as seamlessly as the 2 functions
above. By having no side effects I can just as easily draw dots as
I can connect the dots (it doesn't matter). But they are inefficient
as a result but pretty easy to understand if you walk through it.

to circle3_of_x :x
   localmake "pendown pendownp
   localmake "pos pos
   localmake "head heading
   pu
   home
   setheading :x
   fd 100
   localmake "posxy pos
   if :pendown [pd]
   setpos :pos
   setheading :head   
   output :posxy
end

to spiral3_of_x :x
   localmake "pendown pendownp
   pu
   rt :x
   fd :x/100
   localmake "posxy pos
   bk :x/100
   lt :x
   if :pendown [pd]
   output :posxy
end

Here are the 2 functions that can "draw" any function
that is a function of x (x being angle) and returns
a list containing an x and y coordinate.

to connected_dots :ang :f_of_x
pu
for [a 0 :ang 5] [setpos run list :f_of_x :a pd]
end

to dots :ang :f_of_x
for [a 0 :ang 5] [pu setpos run list :f_of_x :a dot]
end 

Example of how you can call them.

to aaa
cs circle1 messagebox [] []
cs spiral1 messagebox [] []
cs circle2 messagebox [] []
cs spiral2 messagebox [] []
cs circle3 messagebox [] []
cs spiral3 messagebox [] []

cs           dots 360 "circle2_of_x messagebox [] []
cs           dots 720 "spiral2_of_x messagebox [] []
cs           dots 360 "circle3_of_x messagebox [] []
cs           dots 720 "spiral3_of_x messagebox [] []
cs connected_dots 360 "circle2_of_x messagebox [] []
cs connected_dots 720 "spiral2_of_x messagebox [] []
cs connected_dots 360 "circle3_of_x messagebox [] []
cs connected_dots 720 "spiral3_of_x messagebox [] []
end

Lumping the function of the curve together with the drawing of it is
often efficient. But sometimes that makes it inflexible and possibly
confusing if your trying to teach someone about the mathematical function
on a computer the "curve" itself.  You'll notice that the second set
(the ones that uses trig) has the property of being both efficient,
accurate and flexible but has the disadvantage of requiring a trig math
level to understand it.

There is purpose and place for any of these methods.
None it more correct than another unless you put a
context around it such as: age group, efficientcy, or
math vs. programming.

--
===============================================================
George Mills (mills@softronix.com)
http://www.softronix.com/
The www page contains some very powerful educational software.
Our single most important investment is our kids.

---------------------------------------------------------------
Please post messages to the Logo forum to logo-l@gsn.org.  Mail
questions about the list administration to logofdn@gsn.org.  To
unsubscribe send    unsubscribe logo-l    to majordomo@gsn.org.



Global SchoolNet Foundation - Linking Kids Around the World!
Copyright GSN - All Rights Reserved - Comments & Questions
Visit GSN's Global Schoolhouse for more exciting learning resources!
Search our Site - Home