From: James Edward Gray II Date: 2006-12-08T05:27:21+09:00 Subject: Re: Turtle Graphics (#104) On Dec 7, 2006, at 11:15 AM, Edwin Fine wrote: >> # Move forward by turtle steps. >> def forward(steps) >> raise ArgumentError unless steps.is_a?(Numeric) >> @xy = [ @xy.first + sin(@heading * DEG) * steps, >> @xy.last + cos(@heading * DEG) * steps ] >> @track.last << @xy if @pen_is_down >> end > > I think that you should mention a subtlety here. The calculation of a > new point is usually > > [x,y] = [x_old + dist * cos(theta), y_old + dist * sin(theta)] > > Because the turtle geometry is 90 degrees out of phase and rotating in > the other direction, Pete has flipped the x and y so the new point is > > [x,y] = [x_old + dist * sin(theta), y_old + dist * cos(theta)] > > Another subtlety is that Pete used atan2, which handles division by > zero > and the ambiguity of which quadrant you are in. > > (Well, it was subtle to me!!) Both terrific points. Thanks for bringing them up! James Edward Gray II