Toby Donaldson schrieb:
> Gregor.
>
> I am convinced by your argument about the non-elementary nature of
> turtle.towards. I don't think I've ever used this function (or even
> heard of it until you mentioned it!), but it's easy to believe it has
> many uses. So I think it's worth adding.
>
> However, I am not sure if the particular implementation you give for
> towards works in the most natural way. My first reaction is that
> turtle.towards(x,y) ought to make the turtle turn in-place so that it
> points towards (x, y). Your implementation returns an angle, which, to
> me, seems a little more complicated, and somewhat at odds with the
> directness of turtle commands.
Hi Tony,
in this point I disagree with you.
(1) towards() can be used to retrieve (one of the) polar-coordinates of
points, turtles etc relative to a given turtle. In this sense it is
similar to position() in respect to cartesian coordinates. Polar
coordinates are, however, more natural for turtles.
(2) quick (perhaps not ver clever) example: say a turtle should visit a
set of points or meet a collection of other turtles each time starting
from one fixed point. Using towards() it could sort the targets
corresponding to their respective towards-angles in order to decide
which one to visit first ...
(3) functions like
def face(target):
setheading(toward(target))
are very well within the capabilities of programming beginners. This may
even be a good example of what has not necessarily to be provided prebuilt.
(4) On the other hand it is not easy to do the converse, namely to
construct a towards()-like function, which returns the angle, from the
one you proposed - which works without moving the turtle
(5) towards is a standard turtle graphics function (see for instance
MSW-Logo)
Addendum to (1): For the same reason I would strongly recommend to add a
function distanceto(), as was suggested by Chris, which could be used to
retrieve the other polar
coordinate.
Regards,
Gregor
>
> In your demo code towards(x, y) is always called inside setheading,
> and I can't think of any common case where I would want to call
> towards(x, y) without also wanting to set this direction to be the new
> heading. So, I would suggest a change like this:
>
> def toward(self, *args):
> self.setheading(self._towards(*args))
>
> def _towards(self, *args):
> """returns the angle, which corresponds to the line
> from turtle-position to point (x,y).
> Argument can be two coordinates or one pair of coordinates
> or a RawPen/Pen instance.
> """
> if len(args) == 2:
> x, y = args
> else:
> arg = args[0]
> if isinstance(arg, RawPen):
> x, y = arg.position()
> else:
> x, y = arg
> x0, y0 = self.position()
> dx = x - x0
> dy = y - y0
> return (atan2(dy,dx) / self._invradian) % self._fullcircle
>
> Toby
>
>
>
>>I've - as a proposition - added one function to turtlenew:
>>towards(*args), which returns the angle between the line from the turtle
>> to the arg and the positive x-axis-direction. As a demo it's used
>>in demo.py. (The idea is of course taken from Logo, where it is also
>>present) This method uses atan2. So it's not elementary and young
>>students won't be able to program it on their own. So I consider it
>>rather essential. (In fact I incorporated it also into my book-specific
>>turtle.py three years ago - which was also a moderate extension of the
>>original one.)
>
>
> --
> Dr. Toby Donaldson
> School of Computing Science
> Simon Fraser University (Surrey)
>
>
>
>
--
Gregor Lingl
Reisnerstrasse 3/19
A-1030 Wien
Telefon: +43 1 713 33 98
Mobil: +43 664 140 35 27
Website: python4kids.net
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"edupython" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/edupython
-~----------~----~----~----~------~----~------~--~---