
|
Search
Search Loci: Developers: |
Loci: DevelopersConstructing Mathlets Quickly using LiveGraphics3DParametrized GraphicsSo far all of our graphics primitives have had fixed, precomputed numbers as coordinates. One of LiveGraphics3D's most powerful features is its ability to display primitives whose coordinates are not fixed, but depend on independent variables which can be adjusted by the user. These objects are referred to as parametrized graphics. As a basic example, consider the primitive Now let's use this idea to continue building our example. First we add a point to our input file as follows.
(* "mesh" is the same as in the previous example *)
point = {RGBColor[1, 0, 0], PointSize[0.02], Point[{x, y, z}]};
example = Graphics3D[{mesh, point}, Boxed -> False];
WriteLiveForm["meshPoint.lg3d", example]
Because the coordinates in This information is passed to the applet using the INDEPENDENT_VARIABLES and DEPENDENT_VARIABLES parameters. The value for either of these parameters is a list of rules LiveGraphics3D can use to assign values to variables. In the case of independent variables each rule just gives the initial value, which can later be changed by the user. The rules for dependent variables describe how to compute the values using any other previously mentioned variables.
<html><body>
<applet archive="live.jar" code="Live.class" width="500" height="500">
<param name="INPUT_FILE" value="meshPoint.lg3d"/>
<param name="INDEPENDENT_VARIABLES" value="{x -> 1, y -> 0}" />
<param name="DEPENDENT_VARIABLES" value="{z -> 2y*Exp[-x^2-y^2]}"/ >
</applet>
</body></html>
Resulting applet:
Click and drag the red point to see how it moves along the surface. The effect of defining z as a dependent variable is quite noticeable in the following sense: if you view the surface from above, the motion of the point is quite natural; motions of the mouse correspond directly to changes in x and y. If you view the surface from the side, however, the point is very tricky to control. By now you may have noticed that you can drag the point off of the mesh. This undesirable behavior can be avoided with a feature that is tricky and counter-intuitive, yet highly useful: rules for independent variables can also appear in the value of the To understand how this process works, suppose you move the point with the mouse. Internally, LiveGraphics3D will recognize that an independent variable has been changed. Whenever this happens, the rules in the
<html><body>
<applet archive="live.jar" code="Live.class" width="500" height="500">
<param name="INPUT_FILE" value="meshPoint.lg3d"/>
<param name="INDEPENDENT_VARIABLES" value="{x -> 1, y -> 0}" />
<param name="DEPENDENT_VARIABLES" value="{
x -> If[x < -1, -1, x],
x -> If[x > 3, 3, x],
y -> If[y < -2, -2, y],
y -> If[y > 1, 1, y],
z -> 2y*Exp[-x^2-y^2]}" />
</applet>
</body></html>
Resulting applet:
Before continuing, we should mention the following issues related to this example.
|