Line tracing

Jim Hurley jhurley at infostations.com
Sun Feb 2 06:44:24 EST 2003


>  Roger Guay  wrote:
>
>Thanks to all who have responded to this Line tracing thing.  Here is
>another iteration.

(snip)

>
>I've briefly looked at your TurtleGraphicsDemo and I'm very impressed. 
>I haven't had time to understand the "Turtle" aspect yet, but I will
>have a closer look.  I've been toying with the idea of simulating a
>typical Science Museum Foucault Pendulum, where a beautiful pattern is
>traced in the sand by the pendulum.  I would like to generate those
>patterns by running the equation of motion of the Foucault Pendulum.  I
>think this is not going to be easy because if I recall correctly, this
>is a non-linear differential equation.  But, I'm ignorant enough to
>proceed anyway.


Roger,

There is a real catch in solving the Foucault Pendulum problem. The 
equations of motion have no closed form solution. (Although there are 
approximate solutions for small amplitude and for small angular 
velocity.) But if you employ the method illustrated in the Turtle 
Graphics Demo you don't need the solution, you effectively solve the 
equations of motion with a very simple algorithm:

repeat
    xNew = xOld + velocityOld*t
    velocityNew = velocityOld + acceleration*t
    (put the  new x into the old x and draw the line)
    (put the new velocity into the old velocity)
end repeat

where t is some fixed small time increment, and the acceleration is a 
known function.

If for simplicity you take t = 1 (sec), the TG code for *any* problem 
in dynamics  is:

Repeat forever --Or until you lose patience
   IncrementXY vx, vy
   add accx() to  vx
   add accy() to vy
end repeat

The line "IncrementXY vx,vy" increments the x and y coordinates of 
the path by vx and vy, and simultaneously draws the  line.

It doesn't get much simpler. This becomes a template for solving 
*all* such problems in dynamics. You  just  have to write different 
acceleration functions depending on the physical circumstances. You 
can see why I am promoting Transcript/TG as a mean of teaching 
programing to high school science students.

This algorithm is in effect the solution to the differential equation 
of motion by the  method of finite differences, but I wouldn't tell 
anybody--they will shun you.

May I suggest the two dimensional harmonic oscillator rather than the 
Foucault Pendulum. You get beautiful Lissajou figures (prettier than 
the  Foucault path) which are open or closed depending on the ratio 
of the x  and y spring constants. This is a very rich problem for 
exploration.

Good luck. You look like you are having fun.

Jim



More information about the use-livecode mailing list