LiveGraphics3D Example:
Construction of a Spirograph



A Simple Animation with Animate

This is a first simple animation for a Spirograph using Animate. A Spirograph is the curve traced by a fixed point on a circle rolling inside a fixed circle. (This is more or less a defintion by Eric W. Weisstein. The actual curve is not part of this animation.) Animate is a Mathematica command to produce parametrized animations.

In order to define a parametrized animation in LiveGraphics3D, we have to declare the time variable (t in our case) of Animate not only in the Animate command, but also as an independent variable of the applet, i.e. we set

   <PARAM NAME=INDEPENDENT_VARIABLES VALUE="{t->0}">
We also define some dependent variables in order to avoid multiple evaluations of the same expression:
   <PARAM NAME=DEPENDENT_VARIABLES VALUE="
   {R->10, r->2, rho->1,
   xR->R Cos[t], yR->R Sin[t],
   xr->(R-r)Cos[t], yr->(R-r)Sin[t],
   xrho->xr+rho Cos[R/r t],yrho->yr-rho Sin[R/r t]}">
R is going to be the radius of the fixed circle, r the radius of the rolling circle, rho the distance of the traced point to the center of the rolling circle. (xR,yR) is the point where the two circles touch each other, (xr,yr) is the center of the rolling circle and (xrho,yrho) is the traced point.

Unfortunately, the actual Animate command has to contain a Graphics3D object for LiveGraphics3D; therefore, we have to provide z coordinates and appropriate options.

   <PARAM NAME=INPUT VALUE="Animate[Graphics3D[
   {Line[{{0,0,0},{xr,yr,0}}],Line[{{xr,yr,0},{xrho,yrho,0}}],
   PointSize[0.03],Point[{0,0,0}],Point[{xR,yR,0}],
   Point[{xr,yr,0}],Point[{xrho,yrho,0}]},
   ViewPoint->{0,0,10},ViewVertical->{0,1,0},Boxed->False,
   PlotRange->{{-11,11},{-11,11},{-0.5,0.5}}],
   {t,0,6.2831853,0.1}]">
Instead of using the INPUT parameter, we could, of course, also put the Animate command into a file and specify the file name with the INPUT_FILE parameter.

The rest of the APPLET tag has to be set the same way as for static graphics without parameters.

The Graphics3D object may contain any static primitives; thus, with Mathematica we could easily add the circles and the traced curve. Before we do so, however, we will modify the animation to allow the user to manipulate the values of R, r and rho.



A Parametrized Animation

As the user may only manipulate points, we declare the coordinates of the points (xR,yR), (xr,yr), and (xrho,yrho) as independent variables:

   <PARAM NAME=INDEPENDENT_VARIABLES VALUE="{t->0,
   xR->10,yR->0,xr->8,yr->0,xrho->9,yrho->0}">

With these declaration, the user may now drag the three mentioned points and thereby manipulate the values of their coordinates. However, the actual parameters are R, r, and rho; therefore, we calculate the values of these dependent variables from the coordinates. We also reassign the coordinates in order to keep the graphics consistent.

   <PARAM NAME=DEPENDENT_VARIABLES VALUE="{R->Sqrt[xR*xR+yR*yR],
   r->Sqrt[(xR-xr)*(xR-xr)+(yR-yr)*(yR-yr)],
   rho->Sqrt[(xr-xrho)*(xr-xrho)+(yr-yrho)*(yr-yrho)],
   xR->R Cos[t], yR->R Sin[t],
   xr->(R-r)Cos[t],yr->(R-r)Sin[t],
   xrho->xr+rho Cos[R/r t],yrho->yr-rho Sin[R/r t]}">

We do not need to modify the Animate command. However, the period of the animation depends now on r and R. Therefore, our animation may now be discontinuous. Also, the calculation of rho is unstable if the point (xr,yr) is moved, as it is affected by the inconsistency which is cured later by the reassignment of xr and yr.



A More Complex Parametrized Animation

We avoid the problems mentioned above by three modifications: We restrict r to values which produce a periodic motion; we increase the interval for the time variable t correspondingly in order to allow longer periods (6 * 2 Pi); and we calculate rho from consistent coordinates xr and yr. For the computation of rho, we calculate new (helper) coordinates xrh and yrh right after we have calculated the new r. Note that we need the old value of t for this calculation, which we save from the last frame in a new independent variable told. (It may not be a dependent variable because it has to be used in the list of dependent variables before it is set.)

Thus, the only new independent variable is told:

   <PARAM NAME=INDEPENDENT_VARIABLES VALUE="{t->0,told->0,
   xR->10,yR->0,xr->8,yr->0,xrho->9,yrho->0}">
The new dependent variables are xrh and yrh. Also, the computation of r was modified:
   <PARAM NAME=DEPENDENT_VARIABLES VALUE="{R->Sqrt[xR*xR+yR*yR],
   r->6*R/Round[6*R/Sqrt[(xR-xr)*(xR-xr)+(yR-yr)*(yR-yr)]],
   xrh->(R-r)Cos[told],yrh->(R-r)Sin[told],
   rho->Sqrt[(xrh-xrho)*(xrh-xrho)+(yrh-yrho)*(yrh-yrho)],
   xR->R Cos[t], yR->R Sin[t],
   xr->(R-r)Cos[t],yr->(R-r)Sin[t],
   xrho->xr+rho Cos[R/r t],yrho->yr-rho Sin[R/r t],
   told->t}">

In the Animate command the time variable t runs now from 0 to 6 * 2 Pi = 37.699112.

Finally, we should add the circles and the actual trace. The construction of these curves with Mathematica is straightforward; the result is shown on this page.



Martin Kraus, April 16, 2021