Search

Keyword

# Constructing Mathlets Quickly using LiveGraphics3D

## Animations

Parametrized graphics can be very useful, but at times you might want certain graphics primitives to move in a prearranged fashion. LiveGraphics3D facilitates this by providing another format for its input. Instead of

 Graphics3D[ primitives, options ] 

we use the form

 Animate[ Graphics3D[ primitives, options ], {t, tmin, tmax, tstep} ] 

This is demonstrated in the following applet, which shows a very simple model of a solar system. The three points in the applet are located at {x0,y0,z0}, {x1,y1,z1} and {x2,y2,z2}; these coordinates are automatically adjusted by LiveGraphics3D to create an animation. Look at the parameters for the independent and dependent variables to see if you can predict what will happen as t increases from 0 to 2π; move the mouse pointer over the applet to start the animation. In some browsers it may be necessary to click on the applet before the motion begins.

<html><body>
<applet archive="live.jar" code="Live.class" width="500" height="500">
<param name="INPUT"
value="Animate[
Graphics3D[{
RGBColor[ 1, .5,  0],PointSize[0.1], Point[{x0,y0,z0}],
RGBColor[ 0,  0,  1],PointSize[0.05],Point[{x1,y1,z1}],
RGBColor[.5, .5, .5],PointSize[0.03],Point[{x2,y2,z2}]},
PlotRange->{{-2,2}, {-2,2}, {-1,1}},
Axes -> True, AxesLabel -> {X, Y, Z}],
{t, 0, 6.2831, 0.1}]" />
<param name="INDEPENDENT_VARIABLES"
value="{t -> 0, x0 -> 0, y0 -> 0, z0 -> 0 }" />
<param name="DEPENDENT_VARIABLES" value="{
x0 -> If[ x0 < -2, -2, If[ x0 > 2, 2, x0 ]],
y0 -> If[ y0 < -2, -2, If[ y0 > 2, 2, y0 ]],
z0 -> If[ z0 < -1, -1, If[ z0 > 1, 1, z0 ]],
x1 -> x0 + 1.5*Cos[t],
y1 -> y0 + 1.5*Sin[t],
z1 -> z0,
x2 -> x1 + 0.5*Cos[3*t],
y2 -> y1 + 0.5*Sin[3*t],
z2 -> z1}" />
</applet>
</body></html>

Resulting Applet:

As you can verify, LiveGraphics3D still allows you to rotate or zoom in and out while the animation is running. It is also possible to combine animations and parametrized graphics. Notice that x0, y0 and z0 are independent variables in this example. If you double-click the applet to stop the animation, you can drag the orange point {x0,y0,z0} anywhere in the bounding box; double-click the applet again to restart the system in its new location. If you wish to move through an animation frame-by-frame, click the picture with the right mouse button and drag the mouse horizontally. (In MacOS using a mouse with a single button, you can step through the animation frame-by-frame by holding down the Command or Apple key, clicking with the single button, and dragging horizontally.)