[Thread Prev] [Thread Next]
Hello,
Here's two bad answers just for fun.
With a constructivist mind, think about how you would "walk" an oval (in the
same terms as the classic "circle" description: walk a bit turn a bit). An
oval could be described as:
For a while (1 fourth of a full turn), walk a bit and turn a bit, but at
each step, make it a longer step.
Then for the next while (another fourth), walk a bit and turn a bit, but at
each step, make it a shorter step
Repeat the two instructions above.
This can be coded as:
to oval
make "dist 0.05
repeat 90 [fd :dist rt 1 make "dist :dist + 0.05]
repeat 90 [fd :dist rt 1 make "dist :dist - 0.05]
repeat 90 [fd :dist rt 1 make "dist :dist + 0.05]
repeat 90 [fd :dist rt 1 make "dist :dist - 0.05]
end
Try it, you will see that it makes an imperfect oval. Try to figure out why.
A much less constructive approach consists of recoding the C++ algorithm
found in the QuickDraw package (thx Wiki). The oval is perfect but the fun
is totally gone.
x1 - x coordinate of the most left point of the ellipse
x2 - x of the most right point of the ellipse
y1 - y of the lowest point of ellipse
y2 - y of the highest point of ellipse
to oval2 :hsize :vsize
make "x1 minus :hsize
make "x2 :hsize
make "y1 minus :vsize
make "y2 :vsize
make "a abs (0.5 * (:x2 - :x1))
make "b abs (0.5 * (:y2 - :y1))
make "inc pi * 2 / (:a + :b)
make "centx (:x1 + :x2 + 0.5) * 0.5
make "centy (:x1 + :x2 + 0.5) * 0.5
pu setpos se :centx + :a :centy pd
dotimes [i 360] [setpos se ((:centx + :a) * cos :i) ((:centy - :b) * sin
:i)]
end
Execute
oval2 150 50
********
ORIGINAL C++ CODE:
void _ellipse(int x1, int y1, int x2, int y2)
{
double t, a, b, tinc, centx, centy;
a = fabs(.5 * (double)(x2 - x1));
b = fabs(.5 * (double)(y2 - y1));
tinc = PI * 2 / (a + b);
centx = (double)((x1 + x2) + .5) * .5;
centy = (double)((y1 + y2) + .5) * .5;
_moveto(centx + a, centy);
for(t = 0; t < PI * 2; t += tinc)
_lineto(centx + a * cos(t), centy - b * sin(t));
-----Original Message-----
From: mwforum-admin@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
[mailto:mwforum-admin@xxxxxxxxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Russell, Ken
Sent: March 8, 2007 1:29 PM
To: mwforum@xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Subject: oval question
How would one write a procedure to create an oval in logo? I think it will
use a little trig in there (sin?), but I'm (really) unclear on the concept.
Wikipedia has some interesting information, one point being that the term
oval is somewhat unclear. I'm thinking of a squished circle that is
symmetric on two axis.
If anyone can help, my student would appreciate it!
Thanks in advance.
Previous by thread:
Re: oval question
Next by thread:
Re: oval question
To save an attachment to your computer, PC users should right-click (Mac users, click and hold the mouse button) on the link and then choose 'save target as' from the pop-up menu. A window will then pop up in which you can choose a location for the file.
|