The message below is being cross-posted from the LogoForum. Please
reply here at comp.lang.logo and it will be crossposted back to the
LogoForum. The original author of this message is
mjsandy@[EMAIL PROTECTED]
's program for an ellipse is from
Turtle Geometry; Abelsson & diSessa. It is given in chapter 1,
but the explanation is not given until vectors are dealt with in
Chapter 3.
TO ELLIPSE :S :E
LOCAL "N
MAKE "N 0
REPEAT 360[RT :N FD :S LT :N LT :N FD :S * :E RT :N MAKE "N :N + 1]
END
The explanation using vectors may be of interest. A turtle generates
a vector whenever it moves i.e. produces a line which has a length and a
direction!
to vector :length :direction
seth :direction
pd fd :length pu
end
Any two vectors (line segments) can be "added" together to form a third
vector(line segment).
v0 + v1 = v2
The order of addition is not important: v1 + v0 = v2
A regular polygon consists of a set of vectors of the same length
but each differing from its neighbour by a fixed angle, which is a
factor of 360. So the direction of each vector is a multiple of the
fixed angle.
to poly :length :num_sides
make "ang 360/:num_sides
cs
(repeat :num_sides
[ vector :length repcount*:ang ])
end
An important result is such a set of vectors form a closed curve;
the sum of the vectors is zero (has zero length ).
v1+v2+...+vn = 0 (n is the number of sides)
This means that polygons can be combined. Which is the explanation of
the ELLIPSE program.
to ellipse :e
cs ht pu
plot 2 1 2*:e -1
end
to plot :s1 :a1 :s2 :a2
(repeat 360
[vector :s1 repcount*:a1
vector :s2 repcount*:a2
])
end
On its own each vector generates a circle.
The advantage of this program is that it also generates
spirographs: e.g.
to spiro
cs ht
plot 1.4 2.6 1.4 1 ;use REPEAT 5000[..]
end
The program can be extended further by adding more vectors in the REPEAT!
The curves can be smoothed by using two turtles, one to find the next
point,
the other to draw the line.
Mike