[MWForum]Elliptical orbits for planets
Jeff Knope
mwforum@lists.mathcats.com
Sat, 8 Mar 2003 09:09:53 -0800
Mike wrote:
> The way I used to stop the plot was to determine when the plotting turtle
> had
> rotated thro' 360°.
> For each point determine the heading (h) of the line joining the previous
> point to the point. If the tangent at the starting point has a heading h0,
> then stop when h-h0>360°.
> The problem is that heading values are reduced modulo 360,
> so for h0=10°(say), h-h0 is positive up to h=359.9999.., negative
> from h=0, then positive once it has passed h0.
> So you need to detect h-h0>0 the second time round.
> Use a flag, f. and start with f=0
>
> ifelse :f = 0
> [if (heading - :h0) < 0
> [make "f 1]]
> [if (heading - :h0) > 0[stop]]
> The method I used in my (previous) attachment program is more complicated.
>
> By using a "scout" turtle to find the next point the heading of the
plotting
> turtle will be the h used above - since the segment is plotted by moving
> towards the position found by the "scout".
>
> The simplest position to start the plot is a point on the ellipse along
the
> line of the foci. The tangent is perpendicular to that line.
>
An alternative method is to test the distance between the plotting turtle
and beginning point at the end of each step. When that distance is less
than the fd amount of each step, close the ellipse with a setpos to the
beginning point.
Mike's method of using deflections to determine when a figure is complete is
a good one, and is sometimes the only way. But there are some quirks in
MWLogo to watch out for. Hatch a couple turtles at arbitrary locations, and
from the command center try this:
show distance "t1
102.727795654
towards "t1
show heading
311
Note towards always sets heading to an integer value, which is a terribly
rough approximation. If you are keeping a running total of deflections
based on values supplied by towards, very large errors can accumulate.
To eliminate this problem, I use the following (note the input is a pos, not
a turtle):
to toward :pt
if (first :pt) = (first pos) [ifelse (last :pt) > (last pos) [seth 0
stop][seth 180 stop] ;;;avoids trying to divide by 0 below
make "slope ((last :pt) - (last pos)) / ((first :pt) - (first pos))
ifelse (first :pt) > (first pos) [seth minus ((arctan :slope) - 90][seth
minus ((arctan :slope) + 90]
end
This will provide headings with 9-place precision.
-Jeff