Parametric equations: graphing a parametric curve in space
Download file: SpaceCurveGraph.pg
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 => 'Spiral in 3D',
);
$graph->addCurve([ 't * cos(t)', 't * sin(t)', 't' ], [ 0, 6 * pi, 150 ]);
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 curve is added to the graph with the
addCurve method, which takes takes 2 array references with
each array of length 3. The entries of the first array will be used as
the body of JavaScript functions with parameter t whose
values are the x, y, and z
coordinates, respectively, of a point on the curve. For example,
t * cos(t) would be converted into the JavaScript function
(t) => t * cos(t) for the x-coordinate. The
entries of the second array are the minimum and maximum values for the
parameter t, and the number of samples to use for
t.
BEGIN_PGML [@ $graph->Print @]* END_PGML ENDDOCUMENT();
Statement
Insert the graph into the problem.