Surface Graph

Parametric equations: graphing a parametric curve in space

Complete Code

Download file: SurfaceGraph.pg

POD for Macro Files

PG problem file

Explanation

DOCUMENT();

loadMacros('PGstandard.pl', 'PGML.pl', 'plotly3D.pl', 'PGcourse.pl');

Preamble

The macro plotly3D.pl is used to produce the graph.

$graph = Graph3D(
    height => 300,
    width  => 300,
    title  => 'Sphere',
);

$graph->addSurface(
    [ '3 * sin(v) * cos(u)', '3 * sin(v) * sin(u)', '3 * cos(v)' ],
    [ 0,                     2 * pi,                30 ],
    [ 0,                     pi,                    30 ]
);

Setup

A plotly3D graph is created with the Graph3D function. There are many options as decribed in plotly3D macro documentation. In this example, only the height, width, and title are provided.

A parametric surface is added to the graph with the addSurface method, which takes 3 array references with each array of length 3. These parameters are described below.

  1. The entries of the first array are strings that will be used as the body of a JavaScript function with parameters u and v whose values are the x, y, and z coordinates, respectively, of a point on the surface. For example, 3 * sin(v) * cos(u) becomes (u, v) => 3 * sin(v) * cos(u).
  2. The entries of the second array are the minimum and maximum values for the parameter u, and the number of samples to use for u.
  3. The entries of the third array are the minimum and maximum values for the parameter v, and the number of samples to use for v.
BEGIN_PGML
[@ $graph->Print @]*
END_PGML

ENDDOCUMENT();

Statement

Insert the graph into the problem.