# 3DGraphsParametricSurfaces

## Interactive Graphs of Parametric Surfaces in Three Dimensions

This PG code shows how to generate interactive graphs of parametric surfaces from MathObjects formulas. It uses the Java applet LiveGraphics3D to display the interactive graph.

• Example 1: A sphere.
• Example 2: A Moebius band with some orientation vectors.

Example 1: A sphere.

PG problem file Explanation
```DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
"parserVectorUtils.pl",
"PGcourse.pl",
"LiveGraphicsParametricSurface3D.pl",
);

TEXT(beginproblem());
```

Initialization: We need to include the macros file `LiveGraphicsParametricSurface3D.pl`.

```Context("Numeric");

Context()->variables->are(x=>"Real",y=>"Real",z=>"Real",u=>"Real",v=>"Real");

\$plot = ParametricSurface3D(
Fx => Formula("3*cos(u)*sin(v)"),
Fy => Formula("3*sin(u)*sin(v)"),
Fz => Formula("3*cos(v)"),
uvar => 'u', # theta
vvar => 'v', # phi
umin => 0,
umax =>  2*pi,
vmin =>  0,
vmax =>  pi,
usamples => 15,
vsamples => 15,
axesframed => 1,
xaxislabel => "X",
yaxislabel => "Y",
zaxislabel => "Z",
mesh => 0,
outputtype => 4,
);
```

Setup: We generate a string of plot data using `ParametricSurface3D()`.

Setting `outputtype` to something other than 4 will require you to read the source code of `LiveGraphicsParametricSurface3D.pl` and familiarize yourself with the details of the `LiveGraphics3D` java applet. For more information on how to work with the string of plot data, see Martin Kraus's LiveGraphics3D homepage, and the excellent article by Jonathan Rogness and Martin Kraus Constructing Mathlets Quickly Using LiveGraphics3D.

```Context()->texStrings;
BEGIN_TEXT
\{
Live3Ddata(
\$plot,
image => "sphere.png",
size => [400,400],
tex_size => 600,
tex_center => 1,
scale => 1.1,
);
\}
END_TEXT
Context()->normalStrings;
```

Main Text: To display the string of plot data `\$plot`, we use the `Live3Ddata()` routine provided by the macro `LiveGraphics3D.pl`, which is loaded automatically.

After you construct the graph you like, don't forget to take a screen shot of it and make an image file such as `sphere.png` that will be used in the pdf hardcopy.

```\$showPartialCorrectAnswers = 1;

ENDDOCUMENT();
```

Example 2: A Moebius band with some orientation vectors.

PG problem file Explanation
```DOCUMENT();

"PGstandard.pl",
"MathObjects.pl",
"parserVectorUtils.pl",
"PGcourse.pl",
"LiveGraphicsParametricSurface3D.pl",
);

TEXT(beginproblem());
```

Initialization: We need to include the macros file `LiveGraphicsParametricSurface3D.pl`.

```Context("Numeric");

Context()->variables->are(x=>"Real",y=>"Real",z=>"Real",u=>"Real",v=>"Real");

\$plot1 = ParametricSurface3D(
Fx => Formula("cos(v)+u*cos(v/2)*cos(v)"),
Fy => Formula("sin(v)+u*cos(v/2)*sin(v)"),
Fz => Formula("u*sin(v/2)"),
uvar => 'u',
vvar => 'v',
umin =>  -0.4,
umax =>   0.4,
vmin =>  0,
vmax =>  2*pi,
usamples => 1,
vsamples => 90,
axesframed => 0,
xaxislabel => "X",
yaxislabel => "Y",
zaxislabel => "Z",
mesh => 0,
outputtype => 1,
);

\$plot =
\$beginplot .
"{" .
\$plot1 .
"," .
"{RGBColor[0,1,0],Thickness[0.012],Line[{{-1,0,0},{-0.5,0,0}}],
Line[{{-0.5,0,0},{-0.6,0.1,0}}],Line[{{-0.5,0,0},{-0.6,-0.1,0}}]}" .
"," .
"{RGBColor[1,0,0],Thickness[0.012],Line[{{-1,0,0},{-1.5,0,0}}],
Line[{{-1.5,0,0},{-1.4,0.1,0}}],Line[{{-1.5,0,0},{-1.4,-0.1,0}}]}" .
"," .
"{RGBColor[0,0,0],Thickness[0.012],Line[{{0,1,0},{0,0.646,0.353}}],
Line[{{0,0.646,0.353},{0,0.646,0.253}}],Line[{{0,0.646,0.353},{0,0.746,0.353}}]}" .
"," .
"{RGBColor[0,0,0],Thickness[0.012],Line[{{1,0,0},{1,0,0.5}}],
Line[{{1,0,0.5},{1,0.1,0.4}}],Line[{{1,0,0.5},{1,-0.1,0.4}}]}" .
"," .
"{RGBColor[0,0,0],Thickness[0.012],Line[{{0,-1,0},{0,-1.353,0.353}}],
Line[{{0,-1.353,0.353},{0,-1.353,0.253}}],Line[{{0,-1.353,0.353},{0,-1.246,0.353}}]}" .
"}" .
",Axes->False,AxesLabel->{X,Y,Z},Boxed->False" .
"," .
"ViewPoint->{1.618,-2.236,1.956},ViewVertical->{-0.276,0.561,2.6213}" .
\$endplot;

```

Setup: We generate a string of plot data using `ParametricSurface3D()`.

Setting `outputtype` to something other than 4 will require you to read the source code of `LiveGraphicsParametricSurface3D.pl` and familiarize yourself with the details of the `LiveGraphics3D` java applet. For more information on how to work with the string of plot data, see Martin Kraus's LiveGraphics3D homepage, and the excellent article by Jonathan Rogness and Martin Kraus Constructing Mathlets Quickly Using LiveGraphics3D.

```Context()->texStrings;
BEGIN_TEXT
\{
Live3Ddata(
\$plot,
image => "moebius-band.png",
size => [400,400],
tex_size => 600,
tex_center => 1,
scale => 1.1,
);
\}
END_TEXT
Context()->normalStrings;
```

Main Text: To display the string of plot data `\$plot`, we use the `Live3Ddata()` routine provided by the macro `LiveGraphics3D.pl`, which is loaded automatically.

After you construct the graph you like, don't forget to take a screen shot of it and make an image file such as `moebius-band.png` that will be used in the pdf hardcopy.

```\$showPartialCorrectAnswers = 1;

ENDDOCUMENT();
```