% Copyright The Numerical Algorithms Group Limited 1991.
% All rights reserved

% Graphics Page
% @(#)graphics.ht 1.9 91/05/29 15:31:14
%%%%%%%%%%%
%% Pages %%
%%%%%%%%%%%

\begin{page}{GraphicsPage}{Graphics}
\Language{} can plot curves and surfaces of
various types, as well as lists of points in the plane.
\beginscroll
There are two graphics frameworks which you can choose depending on
what type of output you want:
\beginmenu
\menulink{Old Framework}{GraphicsOld} \newline
This framework creates a graphics X window (on platforms that support
this). It can export images to Postscript and XPM bitmap file
formats.
\menulink{New Framework}{GraphicsNew} \newline
Scenegraph based graphics framework, this has a much more regular
structure which has more independence from the number of dimensions
used and the algebra used to represent the geometry.
\newline
There is no capability to create a graphics window, however the
graphics are exported to modern formats (such as SVG and X3D) which
allow the output to be modified and enhanced by specialist graphics
programs such as Inkscape and Blender.
\endmenu
\endscroll
\autobuttons \end{page}

\begin{page}{GraphicsOld}{Old Graphics Framework}
\Language{} can plot curves and surfaces of
various types, as well as lists of points in the plane.
\beginscroll
\beginmenu
\menulink{Examples}{GraphicsExamplePage} \tab{13}
See examples of \Language{} graphics
\menulink{2D Graphics}{TwoDimensionalGraphicsPage} \tab{13}
Graphics in the real and complex plane
\menulink{3D Graphics}{ThreeDimensionalGraphicsPage} \tab{13}
Plot surfaces, curves, or tubes around curves
\menulink{Viewports}{ViewportPage} \tab{13}
Customize graphics using Viewports
\endmenu
\endscroll
\autobuttons \end{page}

\begin{page}{GraphicsNew}{New Graphics Framework}
\beginscroll
The Scenegraph Concept
\newline
\beginmenu
\menulink{Scenegraph Overview}{ScengraphOverviewPage}
Explanation of scenegraph concept
\menulink{Additional Constructs}{GridPage}
Various things can be added to the graphics such as grids and rulers.
\menulink{1 dimension in 2 dimensions}{OneDInTwoDPage}
One Dimensional subspace in Two Dimensions such as a line in a plane.
\menulink{1 dimension in 3 dimensions}{OneDInThreeDPage}
One Dimensional subspace in Three Dimensions such as a line in a 3D space.
\menulink{2 dimensions in 3 dimensions}{TwoDInThreeDPage}
Two Dimensional subspace in Three Dimensions such as a surface in a 3D space.
\menulink{Exporting the graphics}{ExportingPage}
Exporting to SVG, X3D and Obj formats.
\menulink{Example 1}{Example1Page}
Example of how to use the code
\endmenu
\endscroll
\autobuttons \end{page}

\begin{page}{ScengraphOverviewPage}{Scenegraph Concept}
\beginscroll
The Scenegraph Concept
\newline
A scenegraph consists of a number of nodes in a tree structure, the types of
nodes are:
\beginmenu
\menulink{Scenegraph}{ScenegraphPage}
Mode information about scenegraph concept
\menulink{Root Node}{RootNodePage}
Root Node
\menulink{Group Node}{GroupNodePage}
Group Node
\menulink{Line Node}{LineNodePage}
Line Node
\menulink{IFS Node}{IFSNodePage}
Indexed Face Set (IFS) Node
\menulink{Text Node}{TextNodePage}
Text Node
\menulink{Clip Node}{ClipNodePage}
Clip Node
\menulink{Material Node}{MaterialNodePage}
Material Node
\menulink{Transform Node}{TransformNodePage}
Transform Node
%\menulink{ArrowNode}{ArrowNode}
%Arrow Node
\endmenu
\endscroll
\autobuttons \end{page}

\begin{page}{ScenegraphPage}{Scenegraph}
\beginscroll
This tree is constructed by starting with the root node and adding child
nodes using the addChild! function as follows:
\begin{verbatim}
addChild!:(n:%,c:%) -> Void
\end{verbatim}
where 'c' is the child node and 'n' node that it is being added to. Any
node type can be a child node or a parent (although it only makes sense
to put the root node only at the root).
\newline
In general a given node will affect only those nodes under it in the tree
structure.
\newline
The purpose and constructors of these nodes is as follows:
(in the following definitions PT refers to an instance of SPointCategory
such as SCartesian(2),SCartesian(3),SArgand and SConformal).
\endscroll
\autobuttons \end{page}

\begin{page}{RootNodePage}{Root Node}
\beginscroll
Root Node
\newline
Constructs the root node, all other nodes are contained in a tree structure
under this node. The root node can have a bounding box which indicates the
extent where the graphical objects exist. This allows the export code, for
example, to have an area to draw the graphics in.
\begin{verbatim}
createSceneRoot:() -> %
createSceneRoot:(bb: SBoundary(PT)) -> %
createSceneRoot:(minx:I,miny:I,maxx:I,maxy:I) -> %
\end{verbatim}
The parameters define the boundary. This bounding box is intended to
be the area or volume in which the graphical objects are drawn,
elements of the geometry outside this area will not necessarily
be clipped (to be sure use a clipping node with the same boundary).
The bounding box in the root node has these additional effects:
\newline
When exported to a drawing or editing application this defines
the default area available for display of the graphics on the screen.
\newline
It allows some elements such as line widths, font sizes, width of
arrow heads and so on to be scaled so that they are of an
appropriate size for the overall screen area. In mathematical
terms a line has no width but when drawing it we need to give
it a nominal width so that it can be seen.
\newline
If the first version (without boundary information) is used then
the boundary will be calculated, to include all the nodes, when
the scene is first drawn to a file.
\endscroll
\autobuttons \end{page}


\begin{page}{GroupNodePage}{Group Node}
\beginscroll
Group Node
\newline
Constructs a group node, this node does not do anything itself
but contains other nodes. Any node can contain other nodes - we
do not need to use a group node to do this, but if we just want
to group nodes without any other effects then this is a good
choice.
\begin{verbatim}
createSceneGroup:() -> %
addSceneGroup:(n:%) -> %
\end{verbatim}
addSceneGroup is a convenience function which combines the constructor
createSceneGroup with addChild! This allows a scene graph node to be
constructed and added to the scenegraph in one operation.

Most of the scenegraph constructors have this form as an option.
\endscroll
\autobuttons \end{page}

\begin{page}{LineNodePage}{Line Node}
\beginscroll
Line Node
\newline
Constructs a line node, this contains a (possibly curved) line,represented
by a list of points) in n-dimensional space. The dimension of the space is
implicit in the type of points being used.
A Line node can hold a single line or multiple lines. The reason that a
Line node needs to hold multiple lines is that, when a clip is applied
to a line this might break it into several line segments.
\begin{verbatim}
createSceneLine:(line: List PT) -> %
addSceneLine:(n:%,line: List PT) -> %
createSceneLines:(line: LINES) -> %
addSceneLines:(n:%,line: LINES) -> %
\end{verbatim}
Where: LINES==> List List PT
\endscroll
\autobuttons \end{page}

\begin{page}{IFSNodePage}{IFS Node}
\beginscroll
Indexed Face Set (IFS) Node
\newline
Constructs an indexed face set node, this defines a surface in n-dimensional
space represented by a set of polygons in n-dimensional space.
\begin{verbatim}
createSceneIFS:(inx: List List NNI,pts: List PT) -> %
addSceneIFS:(n:%,inx: List List NNI,pts: List PT) -> %
createSceneIFS:(in1: SceneIFS(PT)) -> %
addSceneIFS:(n:%,in1: SceneIFS(PT)) -> %
\end{verbatim}
A specialised constructor for an IFS node constructs a 3D box.
Constructs an indexed face set node which is a 3D box of a given size
\begin{verbatim}
createSceneBox:(size:DF) -> %
addSceneBox:(n:%,size:DF) -> %
\end{verbatim}
\endscroll
\autobuttons \end{page}

\begin{page}{TextNodePage}{Text Node}
\beginscroll
Text Node
\newline
Constructs a text node, text can be used for labelling anything
such as graphs, axes and so on.
\begin{verbatim}
createSceneText:(text: TEXT) -> %
addSceneText:(n:%,text: TEXT) -> %
createSceneText:(str:String,sz:NNI,pz:PT) -> %
addSceneText:(n:%,str:String,sz:NNI,pz:PT) -> %
\end{verbatim}
where: TEXT==> Record(txt:String,siz:NNI,pos:PT)
which defines the text to be printed with its size and position.
\endscroll
\autobuttons \end{page}

\begin{page}{ClipNodePage}{Clip Node}
\beginscroll
Clip Node
\newline
Constructs a clip node, clips its sub nodes in the coordinate
 system in force at the clip node.
\begin{verbatim}
createSceneClip:(bb: SBoundary(PT)) -> %
addSceneClip:(n:%,bb: SBoundary(PT)) -> %
\end{verbatim}
where: bb is the boundary that the node is clipped to.
\endscroll
\autobuttons \end{page}

\begin{page}{MaterialNodePage}{Material Node}
\beginscroll
Material Node
\newline
Constructs a material node
This sets the lineWidth,lineCol and fillCol for all nodes under
this, unless overridden by another material node.
That is the material parameters that apply to a given node are
those of the closest material node above it in the hierarchy
\begin{verbatim}
createSceneMaterial:(mat:MATERIAL) -> %
addSceneMaterial:(n:%,mat:MATERIAL) -> %
createSceneMaterial:(lineW:DF,lineC:String,fillC:String) -> %
addSceneMaterial:(n:%,lineW:DF,lineC:String,fillC:String) -> %
\end{verbatim}
Where: MATERIAL==> Record(lineWidth:DF,lineCol:String,fillCol:String)
\endscroll
\autobuttons \end{page}

\begin{page}{TransformNodePage}{Transform Node}
\beginscroll
Transform Node
\newline
Constructs a transform node
This transforms the points and vectors below this node
If a given node has more than one transform node above
it in the hierarchy then the transforms are concatenated (combined).
\begin{verbatim}
createSceneTransform:(tran:TR) -> %
addSceneTransform:(n:%,tran:TR) -> %
\end{verbatim}
\endscroll
\autobuttons \end{page}

\begin{page}{GridPage}{Grid}
\beginscroll
Drawing Plots and grids
\newline
The following constructors create 'compound' nodes in that the node
returned has subnodes under it.
\newline
Grids and Patterns
\newline
Grids are useful as a background to plots, they consist of various
straight, horizontal and vertical lines.
\newline
The form without the step size constructs a grid with:
\newline
narrow blue lines every 20 units \newline
wide blue lines every 100 units \newline
wide red lines every 200 units \newline
The form with step uses the prevailing colour and thickness and the
step parameter defines the spacing between lines.
\newline
Since the lines in grids are defined by the endpoints of the lines, it
does not make sense to apply a non-linear transform to them as the
lines will remain straight and won't be transformed as they should.
\newline
Patterns are used to show the effect of transforms. Although they may
be approximated by straight lines the points are intended to be close
enough together to transform reasonably accurately.
\newline
The pattern depends on ptype parameter as follows:
\newline
"GRID"::Symbol: construct a set of horizontal and vertical lines in the current
clip boundary and current material with a spacing between
lines given by the step parameter.\newline
"SIERPINSKI"::Symbol: constructs a Sierpinski fractal. Step parameter gives the
level of subdivision.\newline
"HOUSE"::Symbol: constructs a house shape.\newline
\begin{verbatim}
createScenePattern(ptype:Symbol,step:NNI,bb: SBoundary(PT)): %
addScenePattern(n:%,ptype:Symbol,step:NNI,bb: SBoundary(PT)):%
\end{verbatim}
\endscroll
\autobuttons \end{page}

\begin{page}{OneDInTwoDPage}{1 dimension in 2 dimensions}
\beginscroll
One Dimensional subspace in Two Dimensions
\newline
This represents 1 dimension (line - possibly curved) in 2 dimensions (plane)
The line is approximated as end-to-end straight lines defined by a list of
points. In theory a line has no width but in that case we would not see it
so we give it a width given by the material node that is
applicable in this part of the scene graph.
\newline
The plot is defined by a function and a range of values. There are various
ways to define this function:
\newline
DF -> DF a mapping from float to float\newline
DF -> PT a mapping from float to point\newline
\newline
Where:\newline
DF ==> DoubleFloat\newline
PT ==> SPointCategory -- an instance of SPointCategory represents a point.
We can also create the plot using an indirect parameter. (parametric)\newline
PPC is ParametricPlaneCurve(DF -> DF) which is created with curve(f1,f2)\newline
where f1 and f2 are functions of type ComponentFunction, in this case
DF -> DF
\begin{verbatim}
createPlot1Din2D: (f:DF -> PT,tRange:SEG,numPts:NNI) -> %
addPlot1Din2D: (n:%,f:DF -> PT,tRange:SEG,numPts:NNI) -> %
createPlot1Din2D: (DF -> DF,SEG,numPts:NNI) -> %
addPlot1Din2D: (n:%,DF -> DF,SEG,numPts:NNI) -> %
createPlot1Din2Dparametric: (PPC,SEG,numPts:NNI) -> %
addPlot1Din2Dparametric: (n:%,PPC,SEG,numPts:NNI) -> %
\end{verbatim}
\endscroll
\autobuttons \end{page}

\begin{page}{OneDInThreeDPage}{1 dimension in 3 dimensions}
\beginscroll
One Dimensional subspace in Three Dimensions
\newline
create a line (1D subspace) in 3D space
This represents 1 dimension (line - possibly curved) in 3 dimensions.
In theory a line has no width but in that case we would not see it
so we give it a width given by the material node that is
applicable in this part of the scene graph.
\newline
Again there are various ways to define this function:
PCFUN is a function from float to point: DF -> PT
PSC ParametricSpaceCurve(DF -> DF) is created with curve(f1,f2,f3)
where f1,f2 and f3 are functions of type ComponentFunction, in this case
DF -> DF
create a line (1D subspace) in 3D space
\begin{verbatim}
createPlot1Din3Dparametric: (PSC,SEG,numPts:NNI) -> %
addPlot1Din3Dparametric: (n:%,PSC,SEG,numPts:NNI) -> %
createPlot1Din3Dparametric: (PCFUN,SEG,numPts:NNI) -> %
addPlot1Din3Dparametric: (n:%,PCFUN,SEG,numPts:NNI) -> %
\end{verbatim}
\endscroll
\autobuttons \end{page}

\begin{page}{TwoDInThreeDPage}{2 dimension in 3 dimensions}
\beginscroll
Two Dimensional subspace in Three Dimensions (surface)
\newline
create a surface (2D subspace) in 3D space
The surface is approximated by polygons which are
represented by in indexed face set (IFS) node
create a surface (2D subspace) in 3D space
\begin{verbatim}
createPlot2Din3D: (ptFun:PSFUN,uSeg:SEG,vSeg:SEG,numPts:NNI) -> %
createPlot2Din3D: ((DF,DF) -> DF,SEG,SEG,numPts:NNI) -> %
addPlot2Din3D: (n:%,(DF,DF) -> DF,SEG,SEG,numPts:NNI) -> %
createPlot2Din3Dparametric: (PSFUN, SEG, SEG,numPts:NNI) -> %
addPlot2Din3Dparametric: (n:%,PSFUN, SEG, SEG,numPts:NNI) -> %
createPlot2Din3Dparametric: (PSF,SEG,SEG,numPts:NNI) -> %
addPlot2Din3Dparametric: (n:%,PSF,SEG,SEG,numPts:NNI) -> %
\end{verbatim}
\endscroll
\autobuttons \end{page}

\begin{page}{ExportingPage}{Exporting}
\beginscroll
Exporting the graphics
\newline
This scenegraph framework currently exports to the following file formats:
\newline
SVG - For 2 dimensional graphics this is the most standards based and also
        supported by graphical editors such as Inkscape.\newline
X3D - For 3 dimensional graphics I think this is the most standards
        compliant but it is not supported on many 3D editors.\newline
VRML - VRML2 and VRML97 are supported but not VRML1. This flavour of
         VRML holds the same information as X3D but using a different
         non-XML syntax.\newline
Wavefront(obj) - This is a very simple 3D format that will hold meshes
                   but not text or colour information. It is supported on
                   most 3D editors but only use it as a fallback if the
                   other 3D formats don't work.\newline
To export a scenegraph to one of these file formats use the following
function calls:
\newline
Write an 'SVG' representation of node 'n' (usually the root node) to
the filename supplied:
\begin{verbatim}
writeSvg:(n:%,filename:String) -> Void
\end{verbatim}
Write an 'X3D' representation of node 'n' (usually the root node)
to the filename supplied.
\begin{verbatim}
writeX3d:(n:%,filename:String) -> Void
\end{verbatim}
Write a 'VRML' representation of node 'n' (usually the root node)
to the filename supplied.
\begin{verbatim}
writeVRML:(n:%,filename:String) -> Void
\end{verbatim}
Write an 'OBJ' (Wavefront) representation of node 'n' (usually the
root node) to the filename supplied.
\begin{verbatim}
writeObj:(n:%,filename:String) -> Void
\end{verbatim}
If we only want to create an XML structure without writing to a file
we can use these functions:
\newline
create an XmlElement containing a 'SVG' representation of node 'n' and
the nodes below it:
\begin{verbatim}
toSVG:(n:%,mat:MATERIAL,tran:TR,bb: SBoundary(PT)) -> XmlElement
\end{verbatim}
Create an XmlElement containing a 'X3D' representation of node 'n' and
the nodes below it:
\begin{verbatim}
toX3D:(n:%,mat:MATERIAL,tran:TR,bb: SBoundary(PT)) -> XmlElement
\end{verbatim}
Creates .OBJ (Wavefront) structures from scenegraph tree structure called
recursively for each node, so when called on root node in scenegraph
all other nodes in the scenegraph will get called. When called the
reference values should be empty or zero and when the function returns
they will be set.
\begin{verbatim}
toObj:(n:%,ptLst: Reference List PT,_
      indexLst:Reference List List NNI,_
      indexNxt:Reference NNI,tran:TR,bb: SBoundary(PT)) -> Void
\end{verbatim}
\endscroll
\autobuttons \end{page}

\begin{page}{Example1Page}{Example1}
\beginscroll
Using the code
\newline
Example 1 - Two dimensional plots with scale.
First we will create a couple of functions to plot:
\newline
\spadpaste{DF ==> DoubleFloat
\bound{DF} }
\spadpaste{fnsin(x:DF):DF == sin(x/100::DF)*400::DF
\bound{fnsin} }
\spadpaste{fntan(x:DF):DF == tan(x/100::DF)*400::DF
\bound{fntan} }
\newline
Then we create a bounding box, this is the box within which we do the drawing.
This contains two points representing the maximum and minimum extent of the
drawing area or volume. That is mins contains the minimum values of x,y...
and maxs contains the maximum values of x,y...
\newline
\spadpaste{view := boxBoundary(sipnt(0,-500)$SCartesian(2),sipnt(1200,500)$SCartesian(2))$SBoundary(SCartesian(2)) \bound{view} }
\spadpaste{sc := createSceneRoot(view)$Scene(SCartesian(2)) \bound{sc} \free{view}}
\spadpaste{gd := addSceneGrid(sc,view)$Scene(SCartesian(2)) \bound{gd} \free{sc view}}
\newline
we can now export this to a SVG file so that we can confirm that
the scene contains a grid
\newline
\spadpaste{writeSvg(sc,"test1.svg") \free{sc gd}}
\newline
Now lets add a plot to this. First we add a 'material' node to the root to
define the colour and thickness of the plot.
\newline
\spadpaste{mt1 := addSceneMaterial(sc,3::DF,"blue","green")$Scene(SCartesian(2)) \bound{mt1} \free{sc gd DF}}
\newline
Then we add the plot to the material node using the sine function that we
defined earlier.
\newline
\spadpaste{ln1 := addPlot1Din2D(mt1,fnsin,0..1000::DF,49)$Scene(SCartesian(2))
 \bound{ln1} \free{mt1 fnsin DF}}
\newline
we can now export this to a SVG file again to see that
the plot has been added to the grid
\newline
 \spadpaste{writeSvg(sc,"test2.svg") \free{sc ln1}}
\newline
Lets now add second plot to the scene so that we can see how to modify
it using material, transform and clip.
\newline
\spadpaste{mt2 := addSceneMaterial(sc,3::DF,"green","green"
                                  )$Scene(SCartesian(2))
\free{sc DF} \bound{mt2} }
\spadpaste{tr2 := addSceneTransform(mt2,stransform([
             [1::DF,0::DF,0::DF],
             [0::DF,1::DF,0::DF],
             [0::DF,0::DF,1::DF]]))$Scene(SCartesian(2))
\free{mt2} \bound{tr2} }
\spadpaste{bb := boxBoundary(sipnt(100,-400)$SCartesian(2),sipnt(1100,400)$SCartesian(2))$SBoundary(SCartesian(2)) \bound{bb} }
\spadpaste{bb2 := addSceneClip(tr2,bb)$Scene(SCartesian(2))
\free {tr2 bb} \bound{bb2}}
\spadpaste{ln2 := addPlot1Din2D(bb2,fntan,0..1000::DF,49)$Scene(SCartesian(2))
\free{bb2 fntan DF} \bound{ln2} }
\spadpaste{tx := addSceneText(sc,"sin(theta)",32::NNI,
          sipnt(200,400)$SCartesian(2))$Scene(SCartesian(2))
 \free{sc ln2} \bound{tx} }
\spadpaste{writeSvg(sc,"test3.svg") \free{sc tx}}
\endscroll
\autobuttons \end{page}

% Graphics Example Page

\begin{page}{GraphicsExamplePage}{Examples}
\beginscroll
Here are some examples of \Language{} graphics.
Choose a specific type of graph or choose Assorted Examples.
\beginmenu
\menulink{Assorted Examples}{AssortedGraphicsExamplePage} \newline
Examples of each type of \Language{} graphics.
\menulink{Three Dimensional Graphics}{ThreeDimensionalGraphicsExamplePage} \newline
Plot parametrically defined surfaces of three functions.
\menulink{Functions of One Variable}{OneVariableGraphicsExamplePage} \newline
Plot curves defined by an equation y = f(x).
\menulink{Parametric Curves}{ParametricCurveGraphicsExamplePage} \newline
Plot curves defined by parametric equations x = f(t), y = g(t).
\menulink{Polar Coordinates}{PolarGraphicsExamplePage} \newline
Plot curves given in polar form by an equation r = f(theta).
\menulink{Implicit Curves}{ImplicitCurveGraphicsExamplePage} \newline
Plot non-singular curves defined by a polynomial equation
\menulink{Lists of Points}{ListPointsGraphicsExamplePage} \newline
Plot lists of points in the (x,y)-plane.
% \menulink{Sequences}{SequenceGraphicsExamplePage}
% Plot a sequence a1, a2, a3,...
% \menulink{Complex Functions}{ComplexFunctionGraphicsExamplePage}
% Plot complex functions of a complex variable by means of grid plots.
\endmenu
\endscroll
\autobuttons \end{page}

% Assorted Graphics Example Page

\begin{page}{AssortedGraphicsExamplePage}{Assorted Examples}
\beginscroll
Pick a specific example or choose 'All' to see all the examples.\newline
Function of two variables: z = f(x,y).
\graphpaste{draw(sin(x * y), x = -2.5..2.5, y = -2.5..2.5) \bound{example1}}
Function of one variable: y = f(x).
\graphpaste{draw(sin tan x - tan sin x,x = 0..6) \bound{example2} }
Plane parametric curve: x = f(t), y = g(t).
\graphpaste{draw(curve(sin(t)*sin(2*t), sin(3*t)*sin(4*t)), t = 0..2*\%pi) \bound{example3}}
Space parametric curve: x = f(t), y = g(t), z = h(t).
\graphpaste{draw(curve(sin(t)*sin(2*t), sin(3*t)*sin(4*t), sin(5*t)*sin(6*t)), t = 0..2*\%pi) \bound{example4}}
Polar coordinates: r = f(theta).
\graphpaste{draw(sin(17*t), t = 0..2*\%pi, coordinates == polar) \bound{example5}}
Implicit curves: p(x,y) = 0.
\graphpaste{draw(y^2 + y = x^3 - x, x, y,range == \[-2..2,-2..1\]) \bound{example6}}
Run all examples.
\spadpaste{All \free{example1 example2 example3 example4 example5 example6}}
\endscroll
\autobuttons \end{page}

% Three Dimensional Graphics Example Page

\begin{page}{ThreeDimensionalGraphicsExamplePage}{Three Dimensional Graphics}
Plots of parametric surfaces defined by functions f(u,v), g(u,v), and h(u,v).
Choose a particular example or choose 'All' to see all the examples.
\beginscroll
Pear Surface.
\graphpaste{draw(surface((1+exp(-100*u*u))*sin(\%pi*u)*sin(\%pi*v), (1+exp(-100*u*u))*sin(\%pi*u)*cos(\%pi*v), (1+exp(-100*u*u))*cos(\%pi*u)), u=0..1, v=0..2, title=="Pear") \bound{example1}}
Trigonometric Screw.
\graphpaste{draw(surface(x*cos(y),x*sin(y),y*cos(x)), x=-4..4, y=0..2*\%pi, var1Steps==40, var2Steps==40, title=="Trig Screw") \bound{example2}}
Etruscan Venus. \newline
(click on the draw button to execute this example)
\spadpaste{a := 1.3 * cos(2*x) * cos(y) + sin(y) * cos(x)\bound{a}}
\newline
\spadpaste{b := 1.3 * sin(2*x) * cos(y) - sin(y) * sin(x)\bound{b}}
\newline
\spadpaste{c := 2.5 * cos(y) \bound{c}}
\newline
\graphpaste{draw(surface(a,b,c), x=0..\%pi, y=-\%pi..\%pi, var1Steps==40, var2Steps==40, title=="Etruscan Venus") \free{a b c} \bound{example3}}
Banchoff Klein Bottle. \newline
(click on the draw button to execute this example)
\spadpaste{f:=cos(x)*(cos(x/2)*(sqrt(2) + cos(y))+(sin(x/2)*sin(y)*cos(y)))\bound{f}}
\newline
\spadpaste{g:=sin(x)*(cos(x/2)*(sqrt(2) + cos(y))+(sin(x/2)*sin(y)*cos(y)))\bound{g}}
\newline
\spadpaste{h:=-sin(x/2)*(sqrt(2)+cos(y)) + cos(x/2)*sin(y)*cos(y) \bound{h}}
\newline
\graphpaste{draw(surface(f,g,h), x=0..4*\%pi, y=0..2*\%pi, var1Steps==50, var2Steps==50, title=="Banchoff Klein Bottle") \free{f g h} \bound{example4}}
\newline
\spadpaste{All \free{example1 example2 example3 example4}}
\endscroll
\autobuttons \end{page}

% Functions of One Variable Example Page

\begin{page}{OneVariableGraphicsExamplePage}{Functions of One Variable}
\beginscroll
Plots of functions y = f(x).
Choose a particular example or choose 'All' to see all the examples.
\graphpaste{draw(sin tan x - tan sin x, x = 0..6) \bound{example1}}
\newline
\graphpaste{draw(sin x + cos x, x = 0..2*\%pi) \bound{example2}}
\newline
\graphpaste{draw(sin(1/x), x = -1..1) \bound{example3}}
\newline
\graphpaste{draw(x * sin(1/x), x = -1..1) \bound{example4}}
\newline
\spadpaste{All \free{example1 example2 example3 example4}}
\endscroll
\autobuttons \end{page}

% Parametric Curve Example Page

\begin{page}{ParametricCurveGraphicsExamplePage}{Parametric Curves}
Plots of parametric curves x = f(t), y = g(t).
Pick a particular example or choose 'All' to see all the examples.
\beginscroll
The Lemniscate of Bernoulli.
\graphpaste{draw(curve(cos(t/(1+sin(t)^2)), sin(t)*cos(t)/(1+sin(t)^2)), t = -\%pi..\%pi) \bound{example1}}
Lissajous curve.
\graphpaste{draw(curve(9*sin(3*t/4), 8*sin(t)), t = -4*\%pi..4*\%pi) \bound{example2}}
A gnarly closed curve.
\graphpaste{draw(curve(sin(t)*sin(2*t)*sin(3*t), sin(4*t)*sin(5*t)*sin(6*t)),t = 0..2*\%pi)
             \bound{example3}}
Another closed curve.
\graphpaste{draw(curve(cos(4*t)*cos(7*t), cos(4*t)*sin(7*t)), t = 0..2*\%pi) \bound{example4}}
Run all examples on this page.
\spadpaste{All \free{example1 example2 example3 example4}}
\endscroll
\autobuttons \end{page}

% Polar Coordinates Example Page

\begin{page}{PolarGraphicsExamplePage}{Polar Coordinates}
Plots of curves given by an equation in polar coordinates, r = f(theta).
Pick a particular example or choose 'All' to see all the examples.
\beginscroll
A Circle.
\graphpaste{draw(1,t = 0..2*\%pi, coordinates == polar) \bound{example1} }
A Spiral.
\graphpaste{draw(t,t = 0..100, coordinates == polar) \bound{example2} }
A Petal Curve.
\graphpaste{draw(sin(4*t), t = 0..2*\%pi, coordinates == polar) \bound{example3} }
A Limacon.
\graphpaste{draw(2 + 3 * sin t, t = 0..2*\%pi, coordinates == polar) \bound{example4} }
Run all examples on this page.
\spadpaste{All \free{
%example1
example2 example3 example4}}
\endscroll
\autobuttons \end{page}

% Implicit Curve Example Page

\begin{page}{ImplicitCurveGraphicsExamplePage}{Implicit Curves}
Non-singular curves defined by a polynomial equation p(x,y) = 0
in a rectangular region in the plane.
Pick a particular example or choose 'All' to see all the examples.
\beginscroll
A Conic Section (Hyperbola).
\graphpaste{draw(x * y = 1, x, y, range == \[-3..3, -3..3\]) \bound{example1} }
An Elliptic Curve.
\graphpaste{draw(y^2 + y = x^3 - x, x, y, range == \[-2..2, -2..1\]) \bound{example2} }
Cartesian Ovals.
\spadpaste{p := ((x^2 + y^2 + 1) - 8*x)^2 - (8*(x^2 + y^2 + 1) - 4*x - 1) \bound{p} }
\graphpaste{draw(p = 0, x, y, range == \[-1..11, -7..7\], title == "Cartesian Ovals") \free{p} \bound{example3} }
Cassinian Ovals: two loops.
\spadpaste{q := (x^2 + y^2 + 7^2)^2 - (6^4 + 4*7^2*x^2) \bound{q} }
\graphpaste{draw(q = 0, x, y, range == \[-10..10, -4..4\], title == "Cassinian oval with two loops") \free{q} \bound{example4} }
Run all examples on this page.
\spadpaste{All \free{example1 example2 example3 example4}}
\endscroll
\autobuttons \end{page}

% Lists of Points Example Page

\menulink{Lists of Points}{ListPointsGraphicsExamplePage} \newline

\begin{page}{ListPointsGraphicsExamplePage}{Lists of Points}
\Language{} has the ability to create lists of points in a two dimensional
graphics viewport.  This is done by utilizing the \spadtype{GraphImage} and
\spadtype{TwoDimensionalViewport} domain facilities.
\beginscroll
\indent{5}\newline
{\em NOTE:  It is only necessary to click on the makeViewport2D command button to plot this curve example}.
\indent{0}\newline
\spadpaste{p1 := point [1::SF,1::SF]\$(Point SF) \bound{p1}}
\newline
\spadpaste{p2 := point [0::SF,1::SF]\$(Point SF) \bound{p2}}
\newline
\spadpaste{p3 := point [0::SF,0::SF]\$(Point SF) \bound{p3}}
\newline
\spadpaste{p4 := point [1::SF,0::SF]\$(Point SF) \bound{p4}}
\newline
\spadpaste{p5 := point [1::SF,.5::SF]\$(Point SF) \bound{p5}}
\newline
\spadpaste{p6 := point [.5::SF,0::SF]\$(Point SF) \bound{p6}}
\newline
\spadpaste{p7 := point [0::SF,0.5::SF]\$(Point SF) \bound{p7}}
\newline
\spadpaste{p8 := point [.5::SF,1::SF]\$(Point SF) \bound{p8}}
\newline
\spadpaste{p9 := point [.25::SF,.25::SF]\$(Point SF) \bound{p9}}
\newline
\spadpaste{p10 := point [.25::SF,.75::SF]\$(Point SF) \bound{p10}}
\newline
\spadpaste{p11 := point [.75::SF,.75::SF]\$(Point SF) \bound{p11}}
\newline
\spadpaste{p12 := point [.75::SF,.25::SF]\$(Point SF) \bound{p12}}
\newline
\spadpaste{llp := [[p1,p2],[p2,p3],[p3,p4],[p4,p1],[p5,p6],[p6,p7],[p7,p8],[p8,p5],[p9,p10],[p10,p11],[p11,p12],[p12,p9]] \bound{llp} \free{p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12}}
\newline
\spadpaste{size1 := 6::PositiveInteger \bound{size1}}
\newline
\spadpaste{size2 := 8::PositiveInteger \bound{size2}}
\newline
\spadpaste{size3 := 10::PositiveInteger \bound{size3}}
\newline
\spadpaste{lsize := [size1, size1, size1, size1, size2, size2, size2, size2, size3, size3, size3, size3] \bound{lsize} \free{size1 size2 size3}}
\newline
\spadpaste{pc1 := pastel red() \bound{pc1}}
\newline
\spadpaste{pc2 := dim green() \bound{pc2}}
\newline
\spadpaste{pc3 := pastel yellow() \bound{pc3}}
\newline
\spadpaste{lpc := [pc1, pc1, pc1, pc1, pc2, pc2, pc2, pc2, pc3, pc3, pc3, pc3] \bound{lpc} \free{pc1 pc2 pc3}}
\newline
\spadpaste{lc := [pastel blue(), light yellow(), dim green(), bright red(), light green(), dim yellow(), bright blue(), dark red(), pastel red(), light blue(), dim green(), light yellow()] \bound{lc}}
\newline
\spadpaste{g := makeGraphImage(llp,lpc,lc,lsize)\$GRIMAGE \bound{g} \free{llp lpc lc lsize}}
\newline
\graphpaste{makeViewport2D(g,[title("Lines")])\$VIEW2D \free{g}}
The \spadfun{makeViewport2D} command takes a list of options as a parameter
in this example.  The string "Lines" is designated as the viewport's title.
\endscroll
\autobuttons \end{page}

% Three Dimensional Graphics Page

\begin{page}{ThreeDimensionalGraphicsPage}{Three Dimensional Graphing}
\beginscroll
\beginmenu
\menulink{Functions of Two Variables}{TwoVariableGraphicsPage} \newline
Plot surfaces defined by an equation z = f(x,y).
\menulink{Parametric Curves}{SpaceCurveGraphicsPage} \newline
Plot curves defined by equations x = f(t), y = g(t), z = g(t).
\menulink{Parametric Tube Plots}{ParametricTubeGraphicsPage} \newline
Plot a tube around a parametric space curve.
\menulink{Parametric Surfaces}{ParametricSurfaceGraphicsPage} \newline
Plot surfaces defined by x = f(u,v), y = g(u,v), z = h(u,v).
\menulink{Building Objects}{ugGraphThreeDBuildPage} \newline
Create objects constructed from geometric primitives.
\endmenu
\endscroll
\autobuttons \end{page}

% Functions of Two Variables Graphics Page

\begin{page}{TwoVariableGraphicsPage}{Functions of Two Variables}
\beginscroll
This page describes the plotting of surfaces defined by an equation
of two variables, z = f(x,y), for which the ranges of x and y are explicitly
defined.  The basic draw command for this function utilizes either the
uncompiled function or compiled function format.  The general format for an
uncompiled function is:
\indent{5}\newline
{\em draw(f(x,y), x = a..b, y = c..d)}
\indent{0}\newline
where a..b and c..d are segments defining the intervals [a,b] and [c,d] over
which the variables x and y span.  In this case the function is not compiled
until the draw command is executed.  Here is an example:
\graphpaste{draw(cos(x*y),x=-3..3,y=-3..3)}
In the case of a compiled function, the function is named and compiled
independently.  This is useful if you intend to use a function often, or
if the function is long and complex.  The following line shows a function
whose parameters are of the type Small Float. The function is compiled and
stored by \Language{} when it is entered.
\indent{5}\newline
{\em NOTE:  It is only necessary to click on the draw command button to plot
this example}.
\indent{0}\newline
\spadpaste{f(x:SF,y:SF):SF == sin(x)*cos(y) \bound{f}}
\newline
Once the function is compiled the draw command only needs the name of the
function to execute.  Here is a compiled function example:
\graphpaste{draw(f,-\%pi..\%pi,-\%pi..\%pi) \free{f}}
Note that the parameter ranges do not take the variable names as in the
case of uncompiled functions.  The variables are entered in the order in
which they are defined in the function specification.  In this case the
first range specifies the x-variable and the second range specifies the
y-variable.
\endscroll
\autobuttons \end{page}

% Parametric Space Curves Graphics Page

\begin{page}{SpaceCurveGraphicsPage}{Parametric Space Curves}
\beginscroll
This page describes the plotting in three dimensional space of a curve
defined by the parametric equations x = f(t), y = g(t), z = h(t), where
f, g, and h are functions of the parameter t which ranges over a specified
interval.  The basic draw command for this function utilizes either the
uncompiled functions or compiled functions format and uses the \spadfun{curve}
command to specify the three functions for the x, y, and z components of
the curve.  The general format for uncompiled functions is:
\indent{5}\newline
{\em draw(curve(f(t),g(t),h(t)), t = a..b)}
\indent{0}\newline
where a..b is the segment defining the interval [a,b] over which the
parameter t ranges.  In this case the functions are not compiled until the
draw command is executed.  Here is an example:
\graphpaste{draw(curve(cos(t),sin(t),t), t=-12..12)}
In the case of compiled functions, the functions are named and compiled
independently.  This is useful if you intend to use the functions often, or
if the functions are long and complex.  The following lines show functions
whose parameters are of the type Small Float. The functions are compiled and
stored by \Language{} when entered.
\indent{5}\newline
{\em NOTE:  It is only necessary to click on the draw command button to plot
this example}.
\indent{0}\newline
\spadpaste{i1(t:SF):SF == sin(t)*cos(3*t/5) \bound{i1}}
\spadpaste{i2(t:SF):SF == cos(t)*cos(3*t/5) \bound{i2}}
\spadpaste{i3(t:SF):SF == cos(t)*sin(3*t/5) \bound{i3}}
Once the functions are compiled the draw command only needs the names of
the functions to execute.  Here is a compiled functions example:
\graphpaste{draw(curve(i1,i2,i3),0..15*\%pi) \free{i1 i2 i3}}
Note that the parameter range does not take the variable name as in the
case of uncompiled functions. It is understood that the indicated range
applies to the parameter of the functions, which in this case is t.
\endscroll
\autobuttons \end{page}

% Parametric Tube Plots Graphics Page

\begin{page}{ParametricTubeGraphicsPage}{Parametric Tube Plots}
\beginscroll
This page describes the plotting in three dimensional space of a tube
around a parametric space curve defined by the parametric equations
x = f(t), y = g(t), z = h(t), where f, g, and h are functions of the
parameter t which ranges over a specified interval.  The basic draw command
for this function utilizes either the uncompiled functions or compiled
functions format and uses the \spadfun{curve} command to specify the three
functions for the x, y, and z components of the curve.  This uses the same
format as that for space curves except that it requires a specification for
the radius of the tube.  If the radius of the tube is 0, then the result is
the space curve itself.  The general format for uncompiled functions is:
\indent{5}\newline
{\em draw(curve(f(t),g(t),h(t)), t = a..b, tubeRadius == r)}
\indent{0}\newline
where a..b is the segment defining the interval [a,b] over which the
parameter t ranges, and the tubeRadius is indicated by the variable r.
In this case the functions are not compiled until the draw command is
executed.  Here is an example:
\graphpaste{draw(curve(sin(t)*cos(3*t/5), cos(t)*cos(3*t/5), cos(t)*sin(3*t/5)), t=0..15*\%pi,tubeRadius == .15)}
In the case of compiled functions, the functions are named and compiled
independently.  This is useful if you intend to use the functions often, or
if the functions are long and complex.  The following lines show functions
whose parameters are of the type Small Float. The functions are compiled and
stored by \Language{} when entered.
\indent{5}\newline
{\em NOTE:  It is only necessary to click on the draw command button to plot
this example}.
\indent{0}\newline
\spadpaste{t1(t:SF):SF == 4/(2-sin(3*t))*cos(2*t) \bound{t1}}
\newline
\spadpaste{t2(t:SF):SF == 4/(2-sin(3*t))*sin(2*t) \bound{t2}}
\newline
\spadpaste{t3(t:SF):SF == 4/(2-sin(3*t))*cos(3*t) \bound{t3}}
\newline
Once the function is compiled the draw command only needs the names of the
functions to execute.  Here is a compiled functions example of a trefoil knot:
\graphpaste{draw(curve(t1,t2,t3),0..2*\%pi,tubeRadius == .2) \free{t1 t2 t3}}
Note that the parameter range does not take the variable name as in the
case of uncompiled functions. It is understood that the indicated range
applies to the parameter of the functions, which in this case is t.
Typically, the radius of the tube should be set between 0 and 1.  A radius
of less than 0 results in it's positive counterpart and a radius of greater
than one causes self intersection.
\endscroll
\autobuttons \end{page}

% Parametric Surfaces Graphics Page

\begin{page}{ParametricSurfaceGraphicsPage}{Parametric Surfaces}
\beginscroll
Graphing a surface defined by x = f(u,v), y = g(u,v), z = h(u,v). \newline
This page describes the plotting of surfaces defined by the parametric
equations of two variables, x = f(u,v), y = g(u,v), and z = h(u,v),
for which the ranges of u and v are explicitly defined.  The basic draw
command for this function utilizes either the uncompiled function or
compiled function format and uses the \spadfun{surface} command to specify the
three functions for the x, y and z components of the surface.  The general
format for uncompiled functions is:
\indent{5}\newline
{\em draw(surface(f(u,v),g(u,v),h(u,v)), u = a..b, v = c..d)}
\indent{0}\newline
where a..b and c..d are segments defining the intervals [a,b] and [c,d] over
which the parameters u and v span.  In this case the functions are not
compiled until the draw command is executed.  Here is an example of a
surface plotted using the parabolic cylindrical coordinate system option:
\graphpaste{draw(surface(u*cos(v), u*sin(v),v*cos(u)),u=-4..4,v=0..2*\%pi,
                  coordinates== parabolicCylindrical)}
In the case of compiled functions, the functions are named and compiled
independently.  This is useful if you intend to use the functions often, or
if the functions are long and complex.  The following lines show functions
whose parameters are of the type Small Float. The functions are compiled and
stored by \Language{} when entered.
\indent{5}\newline
{\em NOTE:  It is only necessary to click on the draw command button to plot
this example}.
\indent{0}\newline
\spadpaste{n1(u:SF,v:SF):SF == u*cos(v) \bound{n1}}
\newline
\spadpaste{n2(u:SF,v:SF):SF == u*sin(v) \bound{n2}}
\newline
\spadpaste{n3(u:SF,v:SF):SF == u \bound{n3}}
Once the function is compiled the draw command only needs the names of the
functions to execute.  Here is a compiled functions example plotted using
the toroidal coordinate system option: \newline
\graphpaste{draw(surface(n1,n2,n3), 1.0..4.0, 1.0..4*\%pi,
             coordinates == toroidal(1\$SF)) \free{n1 n2 n3}}
Note that the parameter ranges do not take the variable names as in the
case of uncompiled functions.  The variables are entered in the order in
which they are defined in the function specification.  In this case the
first range specifies the u-variable and the second range specifies the
v-variable.
\endscroll
\autobuttons \end{page}

% Building 3D Objects Graphics Page

\begin{page}{3DObjectGraphicsPage}{Building 3D Objects}
\beginscroll
This page describes the \Language{} facilities for creating three dimensional
objects constructed from geometric primitives.  The \Language{} operation
\spadfun{create3Space()} creates a space to which points, curves, and
polygons can be added using the operations from the \spadtype{ThreeSpace}
domain.  The contents of this space can then be displayed in a viewport
using the \spadfun{makeViewport3D()} command.  It will be necessary to
have these operations exposed in order to use them. \indent{5}\newline
{\em NOTE:  It is only necessary to click on the makeViewport3D command button
to plot this curve example}.
\indent{0}\newline
Initially, the space which will hold the objects must be defined and
compiled, as in the following example:
\spadpaste{space := create3Space()\$(ThreeSpace SF) \bound{space}}
Now objects can be sent to this {\em space} as per the operations allowed by
the \spadtype{ThreeSpace} domain.  The following examples place curves into
{\em space}.
\spadpaste{curve(space,[[0,20,20],[0,20,30],[0,30,30],[0,30,100], [0,20,100],[0,20,110],[0,50,110],[0,50,100],[0,40,100], [0,40,30],[0,50,30],[0,50,20],[0,20,20]]) \bound{curveI}}
\newline
\spadpaste{curve(space,[[0,80,20],[0,70,20],[0,70,110],[0,110,110], [0,120,100],[0,120,70],[0,115,65],[0,120,60],[0,120,30], [0,110,20],[0,80,20],[0,80,30],[0,105,30],[0,110,35]]) \bound{curveB1}}
\newline
\spadpaste{curve(space,[[0,110,35],[0,110,55],[0,105,60],[0,80,60],[0,80,70], [0,105,70],[0,110,75],[0,110,95],[0,105,100],[0,80,100], [0,80,30]]) \bound{curveB2}}
\newline
\spadpaste{closedCurve(space,[[0,140,20],[0,140,110],[0,150,110],[0,170,50], [0,190,110],[0,200,110],[0,200,20],[0,190,20],[0,190,75], [0,175,35],[0,165,35],[0,150,75],[0,150,20]]) \bound{curveM}}
\spadpaste{closedCurve(space,[[200,0,20], [200,0,110], [185,0,110], [160,0,45], [160,0,110], [150,0,110], [150,0,20], [165,0,20], [190,0,85], [190,0,20]]) \bound{curveN}}
\spadpaste{closedCurve(space,[[140,0,20], [120,0,110], [110,0,110], [90,0,20], [100,0,20], [108,0,50], [123,0,50], [121,0,60], [110,0,60], [115,0,90], [130,0,20]]) \bound{curveA}}
\spadpaste{closedCurve(space,[[80,0,30], [80,0,100], [70,0,110], [40,0,110], [30,0,100], [30,0,90], [40,0,90], [40,0,95], [45,0,100], [65,0,100], [70,0,95], [70,0,35], [65,0,30], [45,0,30], [40,0,35], [40,0,60], [50,0,60], [50,0,70], [30,0,70], [30,0,30], [40,0,20], [70,0,20]]) \bound{curveG}}
Once {\em space} contains the desired elements a viewport is created and
displayed with the following command:
\graphpaste{makeViewport3D(space,[title("Curves")])\$VIEW3D \free{space curveI curveB1 curveB2 curveM curveN curveA curveG}}
The parameters for \spadfun{makeViewport3D()} in this example are {\em space},
which is the name of the three dimensional space that was defined, and a
string, "curve", which is the title for the viewport.  The tailing string
{\em \$VIEW3D} exposes the command \spadfun{makeViewport3D()} from the domain
\spadtype{ThreeDimensionalViewport} if these commands are unexposed.
\endscroll
\autobuttons \end{page}

% Two Dimensional Graphics Page

\begin{page}{TwoDimensionalGraphicsPage}{Two Dimensional Graphics}
\beginscroll
\beginmenu
\menulink{Functions of One Variable}{OneVariableGraphicsPage} \newline
Plot curves defined by an equation y = f(x).
\menulink{Parametric Curves}{ParametricCurveGraphicsPage} \newline
Plot curves defined by parametric equations x = f(t), y = g(t).
\menulink{Polar Coordinates}{PolarGraphicsPage} \newline
Plot curves given in polar form by an equation r = f(theta).
\menulink{Implicit Curves}{ImplicitCurveGraphicsPage} \newline
Plot non-singular curves defined by a polynomial equation
\menulink{Lists of Points}{ListPointsGraphicsPage} \newline
Plot lists of points in the (x,y)-plane.
% \menulink{Sequences}{SeqGraphicsPage} \newline
% Plot a sequence a1, a2, a3,...
% \menulink{Complex Functions}{CxFuncGraphicsPage} \newline
% Plot functions of a complex variable using grid plots.
\endmenu
\endscroll
\autobuttons \end{page}

% Functions of One Variable Graphics Page

\begin{page}{OneVariableGraphicsPage}{Functions of One Variable}
\beginscroll
Here we wish to plot a function y = f(x) on an interval [a,b].
As an example, let's take the function y = sin(tan(x)) - tan(sin(x))
on the interval [0,6].
Here is the simplest command that will do this:
\graphpaste{draw(sin(tan(x)) - tan(sin(x)),x = 0..6)}
Notice that \Language{} compiled a function before the graph was put
on the screen.
The expression sin(tan(x)) - tan(sin(x)) was converted to a compiled
function so that it's value for various values of x could be computed
quickly and efficiently.
Let's graph the same function on a different interval and this time
we'll give the graph a title.
The title is a String, which is an optional argument of the command 'draw'.
\graphpaste{draw(sin(tan(x)) - tan(sin(x)),x = 10..16,title == "y = sin tan x - tan sin x")}
Once again the expression sin(tan(x)) - tan(sin(x)) was converted to a
compiled function before any points were computed.
If you want to graph the same function on a number of intervals, it's
a good idea to write down a function definition so that the function
only has to be compiled once.
Here's an example:
\spadpaste{f(x) == (x-1)*(x-2)*(x-3) \bound{f}}
\newline
\graphpaste{draw(f, 0..2, title == "y = f(x) on \[0,2\]") \free{f}}
\newline
\graphpaste{draw(f, 0..4,title == "y = f(x) on \[0,4\]") \free{f}}
Notice that our titles can be whatever we want, as long as they are
enclosed by double quotes.  However, a title which is too long to fit
within the viewport title window will be clipped.
\endscroll
\autobuttons \end{page}

% Parametric Curve Graphics Page

\begin{page}{ParametricCurveGraphicsPage}{Parametric Curves}
\beginscroll
One way of producing interesting curves is by using parametric equations.
Let x = f(t) and y = g(t) for two functions f and g as the parameter
t ranges over an interval \[a,b\].
Here's an example:
\graphpaste{draw(curve(sin(t)*sin(2*t)*sin(3*t), sin(4*t)*sin(5*t)*sin(6*t)), t = 0..2*\%pi)}
Here 0..2*\%pi represents the interval over which the variable t ranges.
In the case of parametric curves, \Language{} will compile two functions,
one for each of the functions f and g.
You may also put a title on a graph.
The title may be an arbitrary string and is an optional argument
to the command 'draw'.
For example:
\graphpaste{draw(curve(cos(t), sin(t)), t = 0..2*\%pi, title == "The Unit Circle")}
If you plan on plotting x = f(t), y = g(t) as t ranges over several intervals,
you may want to define functions f and g, so that they need not be
recompiled every time you create a new graph.
Here's an example:
\spadpaste{f(t:SF):SF == sin(3*t/4) \bound{f}}
\newline
\spadpaste{g(t:SF):SF == sin(t) \bound{g}}
\newline
\graphpaste{draw(curve(f,g), 0..\%pi) \free{f g}}
\newline
\graphpaste{draw(curve(f,g) ,\%pi..2*\%pi) \free{f g}}
\newline
\graphpaste{draw(curve(f,g), -4*\%pi..4*\%pi) \free{f g}}
These examples show how the curve changes as the range of parameter t varies.
\endscroll
\autobuttons \end{page}

% Polar Coordinates Graphics Page

\begin{page}{PolarGraphicsPage}{Polar Coordinates}
\beginscroll
Graphs in polar coordinates are given by an equation r = f(theta) as
theta ranges over an interval.
This is equivalent to the parametric curve x = f(theta) * cos(theta),
y = f(theta) * sin(theta) as theta ranges over the same interval.
You may create such curves using the command 'draw', with the optional
argument 'coordinates == polar'.
Here are some examples:
\graphpaste{draw(1,t = 0..2*\%pi,coordinates == polar, title == "The Unit Circle")}
\newline
\graphpaste{draw(sin(17*t), t = 0..2*\%pi, coordinates == polar, title == "A Petal Curve")}
%When you don't specify an interval, \Language{} will assume that you
%mean 0..2*\%pi.
You may also define your own functions, when you plan on plotting the
same curve as theta varies over several intervals.
\spadpaste{f(t) == cos(4*t/7) \bound{f}}
\newline
\graphpaste{draw(f, 0..2*\%pi, coordinates == polar) \free{f}}
\newline
\graphpaste{draw(f, 0..14*\%pi, coordinates == polar) \free{f}}
For information on plotting graphs in other coordinate systems see the
pages for the \spadtype{CoordinateSystems} domain.
\endscroll
\autobuttons \end{page}

% Implicit Curve Graphics Page

\begin{page}{ImplicitCurveGraphicsPage}{Implicit Curves}
\beginscroll
\Language{} has facilities for graphing a non-singular algebraic curve
in a rectangular region of the plane.
An algebraic curve is a curve defined by a polynomial equation
p(x,y) = 0.
Non-singular means that the curve is "smooth" in that it does not
cross itself or come to a point (cusp).
Algebraically, this means that for any point (a,b) on the curve
(i.e. a point such that p(a,b) = 0), the partial derivatives
dp/dx(a,b) and dp/dy(a,b) are not both zero.
We require that the polynomial have rational or integral coefficients.
Here is a Cartesian ovals algebraic curve example:
(click on the draw button to execute this example)
\spadpaste{p := ((x^2 + y^2 + 1) - 8*x)^2 - (8*(x^2 + y^2 + 1) - 4*x - 1) \bound{p} }
\graphpaste{draw(p = 0, x, y, range == \[-1..11, -7..7\], title == "Cartesian Ovals") \free{p}}
{\em A range must be declared for each variable specified in the algebraic
curve equation}.
\endscroll
\autobuttons \end{page}

% List of Points Graphics Page

\begin{page}{ListPointsGraphicsPage}{Lists of Points}
\beginscroll
\Language{} has the ability to create lists of points in a two dimensional
graphics viewport.  This is done by utilizing the \spadtype{GraphImage} and
\spadtype{TwoDimensionalViewport} domain facilities.
\indent{5}\newline
{\em NOTE:  It is only necessary to click on the makeViewport2D command button
to plot this curve example}.
\indent{0}\newline
In this example, the \spadfun{makeGraphImage} command takes a list of lists of
points parameter, a list of colors for each point in the graph, a list of
colors for each line in the graph, and a list of numbers which indicate the
size of each point in the graph.  The following lines create list of lists of
points which can be read be made into two dimensional graph images.
\spadpaste{p1 := point [1::SF,1::SF]\$(Point SF) \bound{p1}}
\newline
\spadpaste{p2 := point [0::SF,1::SF]\$(Point SF) \bound{p2}}
\newline
\spadpaste{p3 := point [0::SF,0::SF]\$(Point SF) \bound{p3}}
\newline
\spadpaste{p4 := point [1::SF,0::SF]\$(Point SF) \bound{p4}}
\newline
\spadpaste{p5 := point [1::SF,.5::SF]\$(Point SF) \bound{p5}}
\newline
\spadpaste{p6 := point [.5::SF,0::SF]\$(Point SF) \bound{p6}}
\newline
\spadpaste{p7 := point [0::SF,0.5::SF]\$(Point SF) \bound{p7}}
\newline
\spadpaste{p8 := point [.5::SF,1::SF]\$(Point SF) \bound{p8}}
\newline
\spadpaste{p9 := point [.25::SF,.25::SF]\$(Point SF) \bound{p9}}
\newline
\spadpaste{p10 := point [.25::SF,.75::SF]\$(Point SF) \bound{p10}}
\newline
\spadpaste{p11 := point [.75::SF,.75::SF]\$(Point SF) \bound{p11}}
\newline
\spadpaste{p12 := point [.75::SF,.25::SF]\$(Point SF) \bound{p12}}
\newline
\spadpaste{llp := [[p1,p2],[p2,p3],[p3,p4],[p4,p1],[p5,p6],[p6,p7],[p7,p8],[p8,p5],[p9,p10],[p10,p11],[p11,p12],[p12,p9]] \bound{llp} \free{p1 p2 p3 p4 p5 p6 p7 p8 p9 p10 p11 p12}}
\newline
These lines set the point color and size, and the line color for all components
of the graph.
\spadpaste{size1 := 6::PositiveInteger \bound{size1}}
\newline
\spadpaste{size2 := 8::PositiveInteger \bound{size2}}
\newline
\spadpaste{size3 := 10::PositiveInteger \bound{size3}}
\newline
\spadpaste{lsize := [size1, size1, size1, size1, size2, size2, size2, size2, size3, size3, size3, size3] \bound{lsize} \free{size1 size2 size3}}
\newline
\spadpaste{pc1 := pastel red() \bound{pc1}}
\newline
\spadpaste{pc2 := dim green() \bound{pc2}}
\newline
\spadpaste{pc3 := pastel yellow() \bound{pc3}}
\newline
\spadpaste{lpc := [pc1, pc1, pc1, pc1, pc2, pc2, pc2, pc2, pc3, pc3, pc3, pc3] \bound{lpc} \free{pc1 pc2 pc3}}
\newline
\spadpaste{lc := [pastel blue(), light yellow(), dim green(), bright red(), light green(), dim yellow(), bright blue(), dark red(), pastel red(), light blue(), dim green(), light yellow()] \bound{lc}}
\newline
Now the graph image is created and named according to the component
specifications indicated above.  The \spadfun{makeViewport2D} command then
creates a two dimensional viewport for this graph according to the list of
options specified within the brackets.
\spadpaste{g := makeGraphImage(llp,lpc,lc,lsize)\$GRIMAGE \bound{g} \free{llp lpc lc lsize}}
\newline
\graphpaste{makeViewport2D(g,[title("Lines")])\$VIEW2D \free{g}}
The \spadfun{makeViewport2D} command takes a list of options as a parameter.
In this example the string "Lines" is designated as the viewport's title.
\endscroll
\autobuttons \end{page}

% \begin{page}{SequenceGraphicsPage}{Sequences}
% \beginscroll
% \endscroll
% \autobuttons \end{page}

% \begin{page}{ComplexFunctionGraphicsPage}{Complex Functions}
% \beginscroll
% \endscroll
% \autobuttons \end{page}

\begin{page}{ViewportPage}{Stand-alone Viewport}
\beginscroll
To get a viewport on a \HyperName{} page, you first need to
create one in \Language{} and write it out to a
file that \HyperName{} can call up. \newline
For example, here we draw a saddle function and assign
the result to the variable \spad{v}:
\newline
\graphpaste{v := draw(x*x-y*y,x=-1..1,y=-1..1) \bound{v}}
\newline
Now that we've created the viewport, we want to write
the data out to a file. \newline
To do this, we use the \spadfunFrom{write}{ThreeDimensionalViewport} command which takes
the following arguments: the viewport to write out,
the title of the file to write it out to, and an optional
argument telling the write command what type (or types) of
data you want to write in additional to the one \Language{} will
always write out. The optional argument could be
a string, like "pixmap", or a list of strings, like \["postscript","pixmap"\].
\HyperName{} needs a "pixmap" data type to include a graph in a page
so in this case, we write the viewport and tell it to
also write a "pixmap" file, as well:
\newline
\spadpaste{write(v,"saddle","pixmap") \free{v}}
\newline
Now we want to put this viewport into a \HyperName{} page.
Say you've created a viewport and written it out
to a file called "/tmp/mobius". (\Language{} actually
tags a ".VIEW" at the end of a viewport data file to
make it easier to spot when you're rummaging through
your file system, but you needn't worry about that here
since \Language{} will always automatically add on a
".VIEW" for you.)  \newline

{\bf Including Viewports} \newline
To put a viewport in a
\HyperName{} page, include the following line in your \HyperName{}
source code: \newline
\space{5}\\viewport\{/tmp/mobius\} \newline
You will get this on your page: \newline
%%%\space{4}\viewport{/tmp/mobius}\newline
%\space{4}\spadviewport{mobius}\newline
\centerline{\spadviewport{mobius}}\newline

{\bf Creating Viewport Buttons} \newline
To make an active button that would make this viewport
come to life, include the following: \newline
\space{5}\\viewportbutton\{ViewButton\}\{/tmp/mobius\} \newline
this creates this button...\newline
%%%\centerline{\viewportbutton{ViewButton}{/tmp/mobius}}\newline
\centerline{\spadviewportbutton{ViewButton}{mobius}}\newline

{\bf Creating Active Viewports} \newline
To merge the two things described above, namely, getting a picture of a
viewport and creating a button to invoke a live viewport, you can do
the following: \newline

%\space{5}\\viewportasbutton\{/tmp/mobius\} \newline
\centerline{\\viewportasbutton\{/tmp/mobius\}}\newline

This would create a picture of a viewport that is an active
button as well. Try it:

%%%\space{5}\viewportasbutton{/tmp/mobius} \newline
%\space{5}\spadviewportasbutton{mobius} \newline
\centerline{\spadviewportasbutton{mobius}}\newline

{\bf Including Viewports Distributed with \Language{}} \newline
All the above commands have counterparts that allow you to
access viewports that are already packaged with \Language{}.
To include those viewports, just add on a "fricas" prefix
to the above commands: \newline

\centerline{\\spadviewport\{vA\} for \\viewport\{vA\}}
\centerline{\\spadviewportbutton\{vB\} for \\viewportbutton\{vB\}}
\centerline{\\spadviewportasbutton\{vC\} for \\viewportasbutton\{vC\}} \newline

All these macros really do is include some path that
indicates where \Language{} stores the viewports.
\newline
\endscroll
\autobuttons \end{page}
