
|
Search
Search Journal of Online Mathematics and its Applications: |
Journal of Online Mathematics and its ApplicationsConstructing Mathlets Quickly using LiveGraphics3DIncluding TextIn a complicated mathlet, you might want to include text labels for certain points, curves, or other objects. We will illustrate the process here by adding text to the mathlet from the introduction. You may wish to review the construction of this mathlet in the first few pages of the article. Since we will only add text primitives to the scene, most of the code from those pages can be reused. Only the last two commands need to be replaced. With LiveGraphics3D you can label the whole plot and individual axes, and you can put text labels at arbitrary three-dimensional points in your scene. For example, in order to label the blue and green sections with labels
(* all but the last two commands are the same as in the earlier example *)
labels = {Text["x = const.", {x, -2, 0}, {1,1}],
Text["y = const.", {3, y, 0}, {-1,1}]};
example = Graphics3D[
{mesh, point, xSection, ySection, tanplane, labels},
Boxed -> False, Lighting -> False]
WriteLiveForm["meshPlaneText1.lg3d", example]
Resulting applet:
Note that the labels move with the cross sections as you drag the red point because the variables
labels = {Text[StyleForm["x = const.", FontFamily -> "Times",
FontSize -> 20],
{x, -2, 0}, {1,1}],
Text[StyleForm["y = const.", FontFamily -> "Times",
FontSize -> 20],
{3, y, 0}, {-1,1}]};
Most systems support the fonts "Times", "Courier", and "Helvetica"; however, not all special characters are supported in all fonts nor by all systems. In our experience, "Times" usually offers the largest set of special characters. These characters can be entered with their hexadecimal unicode; for example, In order to modify the style of parts of a text label, you can use
labels = {Text[StyleForm[StringForm["`1` = const.",
StyleForm["x", FontSlant -> "Italic"]],
FontFamily -> "Times", FontSize -> 20],
{x, -2, 0}, {1,1}],
Text[StyleForm[StringForm["`1` = const.",
StyleForm["y", FontWeight -> "Bold"]],
FontFamily -> "Times", FontSize -> 20],
{3, y, 0}, {-1,1}]};
Resulting applet:
Apart from static labels, we can also include the value of any variable in a text label. For example, we can replace the string
labels = {Text[StyleForm[StringForm["`1` = `2`", "x", x],
FontFamily -> "Times", FontSize -> 20],
{x, -2, 0}, {1,1}],
Text[StyleForm[StringForm["y = `1`", y],
FontFamily -> "Times", FontSize -> 20],
{3, y, 0}, {-1,1}]};
Resulting applet:
As you drag the red point in this example, the new numeric values of To display a changing numeric value in LiveGraphics3D, the text label must refer to a specific variable. For technical reasons, it is not possible to include arbitrary mathematical expressions within a label; a primitive such as For example, let us display the values of
<applet archive="live.jar" code="Live.class" width="500" height="500">
<param name="INPUT_FILE" value="meshPlaneText4.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],
xDisplay -> Round[100 * x] / 100,
yDisplay -> Round[100 * y] / 100}" />
</applet>
Note the two new variables
labels = {
Text[StyleForm["x = ", FontFamily -> "Times", FontSize -> 20],
{x, -2.5, 0}, {1, 1}],
Text[StyleForm[xDisplay, FontFamily -> "Times", FontSize -> 20],
{x, -2.5, 0}, {-1, 1}],
Text[StyleForm[["y = ", FontFamily -> "Times", FontSize -> 20],
{3.5, y, 0}, {1, 1}],
Text[StyleForm[yDisplay, FontFamily -> "Times", FontSize -> 20],
{3.5, y, 0}, {-1, 1}]
};
Resulting applet:
As mentioned earlier, |