Asymptote: The Vector Graphics Language
Asymptote: The Vector Graphics Language
Asymptote: The Vector Graphics Language
Table of Contents
1 Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 UNIX binary distributions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 MacOS X binary distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Microsoft Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 Configuring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.5 Search paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.6 Compiling from UNIX source . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.7 Editing modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.8 Subversion (SVN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.9 Uninstall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3 Tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
4 Drawing commands . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.1 draw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.2 fill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.3 clip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.4 label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
5 Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.1 Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
5.2 Paths and guides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
5.3 Pens . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
5.4 Transforms. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
5.5 Frames and pictures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
5.6 Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
5.7 Variable initializers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
5.8 Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
5.9 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.9.1 Arithmetic & logical operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
5.9.2 Self & prefix operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.9.3 User-defined operators. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.10 Implicit scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.11 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.11.1 Default arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
5.11.2 Named arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
5.11.3 Rest arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.11.4 Mathematical functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
5.12 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
5.12.1 Slices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
ii
5.13 Casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
5.14 Import. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
5.15 Static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
6 LaTeX usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
7 Base modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.1 plain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.2 simplex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.3 math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.4 interpolate. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.5 geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
7.6 trembling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.7 stats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.8 patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.9 markers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
7.10 tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
7.11 binarytree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
7.12 drawtree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7.13 syzygy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7.14 feynman . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7.15 roundedpath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7.16 animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7.17 embed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
7.18 slide. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.19 MetaPost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.20 unicode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.21 latin1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.22 babel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.23 labelpath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.24 labelpath3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.25 annotate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.26 CAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.27 graph. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.28 palette . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
7.29 three . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
7.30 obj . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
7.31 graph3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
7.32 grid3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
7.33 solids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
7.34 tube. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143
7.35 flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
7.36 contour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
7.37 contour3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
7.38 slopefield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
7.39 ode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
iii
8 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
12 Help. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
13 Debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
14 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164
Chapter 1: Description 1
1 Description
Asymptote is a powerful descriptive vector graphics language that provides a mathematical
coordinate-based framework for technical drawings. Labels and equations are typeset with
LaTeX, for overall document consistency, yielding the same high-quality level of typesetting
that LaTeX provides for scientific text. By default it produces PostScript output, but it
can also generate any format that the ImageMagick package can produce.
A major advantage of Asymptote over other graphics packages is that it is a high-level
programming language, as opposed to just a graphics program: it can therefore exploit the
best features of the script (command-driven) and graphical-user-interface (GUI) methods
for producing figures. The rudimentary GUI xasy included with the package allows one
to move script-generated objects around. To make Asymptote accessible to the average
user, this GUI is currently being developed into a full-fledged interface that can generate
objects directly. However, the script portion of the language is now ready for general use by
users who are willing to learn a few simple Asymptote graphics commands (see Chapter 4
[Drawing commands], page 15).
Asymptote is mathematically oriented (e.g. one can use complex multiplication to rotate
a vector) and uses LaTeX to do the typesetting of labels. This is an important feature for
scientific applications. It was inspired by an earlier drawing program (with a weaker syntax
and capabilities) called MetaPost.
The Asymptote vector graphics language provides:
• a standard for typesetting mathematical figures, just as TEX/LaTeX is the de-facto
standard for typesetting equations.
• LaTeX typesetting of labels, for overall document consistency;
• the ability to generate and embed 3D vector PRC graphics into PDF files;
• a natural coordinate-based framework for technical drawings, inspired by MetaPost,
with a much cleaner, powerful C++-like programming syntax;
• compilation of figures into virtual machine code for speed, without sacrificing
portability;
• the power of a script-based language coupled to the convenience of a GUI;
• customization using its own C++-like graphics programming language;
• sensible defaults for graphical features, with the ability to override;
• a high-level mathematically oriented interface to the PostScript language for vector
graphics, including affine transforms and complex variables;
• functions that can create new (anonymous) functions;
• deferred drawing that uses the simplex method to solve overall size constraint issues
between fixed-sized objects (labels and arrowheads) and objects that should scale with
figure size;
Many of the features of Asymptote are written in the Asymptote language itself. While
the stock version of Asymptote is designed for mathematics typesetting needs, one can write
Asymptote modules that tailor it to specific applications. A scientific graphing module has
already been written (see Section 7.27 [graph], page 93). Examples of Asymptote code and
output, including animations, are available at
Chapter 1: Description 2
http://asymptote.sourceforge.net/gallery/.
Links to many external resources, including an excellent user-written Asymptote tutorial
can be found at
http://asymptote.sourceforge.net/links.html.
Chapter 2: Installation 3
2 Installation
After following the instructions for your specific distribution, please see also Section 2.4
[Configuring], page 4.
We recommend subscribing to new release announcements at
http://freshmeat.net/projects/asy
Users may also wish to monitor the Asymptote forum:
http://sourceforge.net/forum/monitor.php?forum_id=409349
2.4 Configuring
In interactive mode, or when given the -V option (the default when running Asymptote on
a single file under MSDOS), Asymptote will automatically invoke the PostScript viewer gv
(under UNIX) or gsview (under MSDOS to display graphical output. These defaults may be
overridden with the configuration variable psviewer. The PostScript viewer should be
capable of automatically redrawing whenever the output file is updated. The default UNIX
PostScript viewer gv supports this (via a SIGHUP signal). Version gv-3.6.3 or later (from
http://ftp.gnu.org/gnu/gv/) is required for interactive mode to work properly. Users of
ggv will need to enable Watch file under Edit/Postscript Viewer Preferences. Users
of gsview will need to enable Options/Auto Redisplay (however, under MSDOS it is still
necessary to click on the gsview window; under UNIX one must manually redisplay by
pressing the r key). A better (and free) multiplatform alternative to gsview is psview (see
[psview], page 4).
Configuration variables are most easily set as Asymptote variables in an optional
configuration file (by default, .asy/config.asy in the user’s home directory,
$TEXMFCONFIG/asymptote under TeXLive, and %USERPROFILE%\.asy\config.asy under
MSDOS; see [configuration file], page 154). Here are the default values of several important
configuration variables under UNIX:
import settings;
psviewer="gv";
pdfviewer="acroread";
gs="gs";
Chapter 2: Installation 5
Under MSDOS, the (installation-dependent) default values of these configuration variables are
determined automatically from the Microsoft Windows registry. Viewer settings (such as
psviewer and pdfviewer) can be set to the string cmd to request the application normally
associated with the corresponding file type.
For PDF format output, the gs setting specifies the location of the PostScript-to-PDF
processor Ghostscript, available from http://sourceforge.net/projects/ghostscript/.
The setting pdfviewer specifies the location of the PDF viewer. On UNIX
systems, to support automatic document reloading in Adobe Reader, we recommend
copying the file reload.js from the Asymptote system directory (by default,
/usr/local/share/asymptote under UNIX to ~/.adobe/Acrobat/x.x/JavaScripts/,
where x.x represents the appropriate Adobe Reader version number. The automatic
document reload feature must then be explicitly enabled by putting
import settings;
pdfreload=true;
pdfreloadOptions="-tempFile";
in the Asymptote configuration file. This reload feature is not useful under MSDOS since the
document cannot be updated anyway on that operating system until it is first closed by
Adobe Reader.
The configuration variable dir can be used to adjust the search path (see Section 2.5
[Search paths], page 6).
By default, Asymptote attempts to center the figure on the page, assuming that the paper
type is letter. The default paper type may be changed to a4 with the configuration variable
papertype. Alignment to other paper sizes can be obtained by setting the configuration
variables paperwidth and paperheight.
The following configuration variables normally do not require adjustment:
texpath
texcommand
dvips
convert
display
animate
Warnings (such as "writeoverloaded") may be enabled or disabled with the functions
warn(string s);
nowarn(string s);
or by directly modifying the string array warnings.
Configuration variables may also be set or overwritten with a command-line option:
asy -psviewer=gsview -V venn
Alternatively, system environment versions of the above configuration variables may be
set in the conventional way. The corresponding environment variable name is obtained by
converting the configuration variable name to upper case and prepending ASYMPTOTE_: for
example, to set the environment variable
ASYMPTOTE_PSVIEWER="C:\Program Files\Ghostgum\gsview\gsview32.exe";
under Microsoft Windows XP:
Chapter 2: Installation 6
http://asymptote.sourceforge.net/asymptote.pdf
in the directory doc and repeat the command make all.
For a (default) system-wide installation, the last command should be done as the root user.
To install without root privileges, change the ./configure command to
./configure --prefix=$HOME/asymptote
One can disable use of the Boehm garbage collector by configuring with ./configure
--disable-gc. For a list of other configuration options, say ./configure --help. For
example, one can tell configure to look for header files and libraries in nonstandard locations:
./configure CFLAGS=-I/opt/usr/include LDFLAGS=-L/opt/usr/lib
If you are compiling Asymptote with gcc, you will need a relatively recent version (e.g.
3.4.4 or later). For full interactive functionality, you will need version 4.2 or later of the GNU
readline library. The file gcc3.3.2curses.patch in the patches directory can be used
to patch the broken curses.h header file (or a local copy thereof in the current directory) on
some AIX and IRIX systems.
The FFTW library is only required if you want Asymptote to be able to take Fourier
transforms of data (say, to compute an audio power spectrum). The GSL library is only
required if you require the special functions that it supports.
If you don’t want to install Asymptote system wide, just make sure the compiled binary
asy and GUI script xasy are in your path and set the configuration variable dir to point
to the directory base (in the top level directory of the Asymptote source code).
Particularly useful key bindings in this mode are C-c C-c, which compiles and displays the
current buffer, and the key binding C-c ?, which shows the available function prototypes
for the command at the cursor. For full functionality you should also install the Apache
Software Foundation package two-mode-mode:
http://www.dedasys.com/freesoftware/files/two-mode-mode.el
Once installed, you can use the hybrid mode lasy-mode to edit a LaTeX file containing
embedded Asymptote code (see Chapter 6 [LaTeX usage], page 81). This mode can
be enabled within latex-mode with the key sequence M-x lasy-mode <RET>. On UNIX
systems, additional keywords will be generated from all asy files in the space-separated
list of directories specified by the environment variable ASYMPTOTE_SITEDIR. Further
documentation of asy-mode is available within emacs by pressing the sequence keys C-h f
asy-mode <RET>.
Chapter 2: Installation 8
2.9 Uninstall
To uninstall an Linux i386 binary distribution, use the commands
tar -zxvf asymptote-x.xx.i386.tgz | xargs --replace=% rm /%
texhash
To uninstall all Asymptote files installed from a source distribution, use the command
make uninstall
Chapter 3: Tutorial 9
3 Tutorial
An excellent user-written Asymptote tutorial is also available from
http://www.artofproblemsolving.com/Wiki/index.php/Asymptote:_Basics
To draw a line from coordinate (0,0) to coordinate (100,100) using Asymptote’s interactive
mode, type at the command prompt:
asy
draw((0,0)--(100,100));
The units here are PostScript "big points" (1 bp = 1/72 inch); -- means join with a
linear segment. In Asymptote coordinates like (0,0) and (1000,100) are called pairs.
At this point you can type in further draw commands, which will be added to the
displayed figure, or type quit to exit interactive mode. You can use the arrow keys
in interactive mode to edit previous lines (assuming that you have support for the GNU
readline library enabled). The tab key will automatically complete unambiguous words;
otherwise, hitting tab again will show the possible choices. Further commands specific to
interactive mode are described in Chapter 9 [Interactive mode], page 157.
In batch mode, Asymptote reads commands directly from a file. To try this out, type
draw((0,0)--(100,100));
into a file, say test.asy. Then execute this file with the MSDOS or UNIX command
asy -V test
MSDOS users can drag and drop the file onto the Desktop asy icon or make Asymptote the
default application for files with the extension asy.
The -V option opens up a PostScript viewer window so you can immediately view the
encapsulated PostScript output. By default the output will be written to the file test.eps;
the prefix of the output file may be changed with the -o command-line option.
One can draw a line with more than two points and create a cyclic path like this square:
draw((0,0)--(100,0)--(100,100)--(0,100)--cycle);
Chapter 3: Tutorial 10
It is often inconvenient to work directly with PostScript coordinates. The next example
draws a unit square scaled to width 101 bp and height 101 bp. The output is identical to
that of the previous example.
size(101,101);
draw((0,0)--(1,0)--(1,1)--(0,1)--cycle);
For convenience, the path (0,0)--(1,0)--(1,1)--(0,1)--cycle may be replaced with
the predefined variable unitsquare, or equivalently, box((0,0),(1,1)).
One can also specify the size in pt (1 pt = 1/72.27 inch), cm, mm, or inches. If 0 is
given as a size argument, no restriction is made in that direction; the overall scaling will be
determined by the other direction (see [size], page 45):
size(0,3cm);
draw(unitsquare);
D C
A B
Asymptote uses the standard compass directions E=(1,0), N=(0,1), NE=unit(N+E), and
ENE=unit(E+NE), etc., which along with the directions up, down, right, and left are
defined as pairs in the Asymptote base module plain. A user who has a local variable
Chapter 3: Tutorial 11
named E may access the compass direction E by prefixing it with the name of the module
where it is defined: plain.E.
This example draws a path that approximates a quarter circle:
size(100,0);
draw((1,0){up}..{left}(0,1));
In general, a path is specified as a list of pairs (or other paths) interconnected with --,
which denotes a straight line segment, or .., which denotes a cubic spline. Specifying a
final node cycle creates a cyclic path that connects smoothly back to the initial node, as
in this approximation (accurate to within 0.06%) of a unit circle:
path unitcircle=E..N..W..S..cycle;
Each interior node of a cubic spline may be given a direction prefix or suffix {dir}:
the direction of the pair dir specifies the direction of the incoming or outgoing tangent,
respectively, to the curve at that node. Exterior nodes may be given direction specifiers
only on their interior side.
A cubic spline between the node z0 , with postcontrol point c0 , and the node z1 , with
precontrol point c1 , is computed as the Bezier curve
c0 m1 c1
m3 m5 m4
m0
m2
z0 z1
Chapter 3: Tutorial 12
Here m0 , m1 and m2 are the first-order midpoints, m3 and m4 are the second-order
midpoints, and m5 is the third-order midpoint. The curve is then constructed by recursively
applying the algorithm to (z0 , m0 , m3 , m5 ) and (m5 , m4 , m2 , z1 ).
In fact, an analogous property holds for points located at any fraction t in [0, 1] of each
segment, not just for midpoints (t = 1/2).
The Bezier curve constructed in this manner has the following properties:
• It is entirely contained in the convex hull of the given four points.
• It starts heading from the first endpoint to the first control point and finishes heading
from the second control point to the second endpoint.
The user can specify explicit control points between two nodes like this:
draw((0,0)..controls (0,100) and (100,100)..(100,0));
However, it is usually more convenient to just use the .. operator, which tells
Asymptote to choose its own control points using the algorithms described in Donald
Knuth’s monograph, The MetaFontbook, Chapter 14. The user can still customize the
guide (or path) by specifying direction, tension, and curl values.
The higher the tension, the straighter the curve is, and the more it approximates a
straight line. One can change the spline tension from its default value of 1 to any real value
greater than or equal to 0.75 (cf. John D. Hobby, Discrete and Computational Geometry
1, 1986):
draw((100,0)..tension 2 ..(100,100)..(0,100));
draw((100,0)..tension 2 and 1 ..(100,100)..(0,100));
draw((100,0)..tension atleast 1 ..(100,100)..(0,100));
The curl parameter specifies the curvature at the endpoints of a path (0 means straight;
the default value of 1 means approximately circular):
draw((100,0){curl 0}..(100,100)..{curl 0}(0,100));
The MetaPost ... path connector, which requests, when possible, an inflection-free
curve confined to a triangle defined by the endpoints and directions, is implemented in
Asymptote as the convenient abbreviation :: for ..tension atleast 1 .. (the ellipsis ...
is used in Asymptote to indicate a variable number of arguments; see Section 5.11.3 [Rest
arguments], page 64). For example, compare
draw((0,0){up}..(100,25){right}..(200,0){down});
with
draw((0,0){up}::(100,25){right}::(200,0){down});
The --- connector is an abbreviation for ..tension atleast infinity.. and the &
connector concatenates two paths, after first stripping off the last node of the first path
(which normally should coincide with the first node of the second path).
Chapter 3: Tutorial 13
size(0,100);
path unitcircle=E..N..W..S..cycle;
path g=scale(2)*unitcircle;
filldraw(unitcircle^^g,evenodd+yellow,black);
The PostScript even-odd fill rule here specifies that only the region bounded between
the two unit circles is filled (see [fillrule], page 40). In this example, the same effect can be
achieved by using the default zero winding number fill rule, if one is careful to alternate the
orientation of the paths:
filldraw(unitcircle^^reverse(g),yellow,black);
import three;
dotgranularity=0; // Render dots as spheres.
currentprojection=orthographic(5,4,2,center=true);
size(5cm);
size3(3cm,5cm,8cm);
draw(unitbox);
dot(unitbox,red);
label("$O$",(0,0,0),NW);
label("(1,0,0)",(1,0,0),S);
label("(0,1,0)",(0,1,0),E);
label("(0,0,1)",(0,0,1),Z);
Chapter 3: Tutorial 14
See section Section 7.27 [graph], page 93 (or the online Asymptote gallery and external
links posted at http://asymptote.sourceforge.net) for further examples, including two
and three-dimensional scientific graphs. Additional examples have been posted by Philippe
Ivaldi at http://piprim.tuxfamily.org/asymptote/.
Chapter 4: Drawing commands 15
4 Drawing commands
All of Asymptote’s graphical capabilities are based on four primitive commands. The three
PostScript drawing commands draw, fill, and clip add objects to a picture in the order
in which they are executed, with the most recently drawn object appearing on top. The
labeling command label can be used to add text labels and external EPS images, which
will appear on top of the PostScript objects (since this is normally what one wants), but
again in the relative order in which they were executed. After drawing objects on a picture,
the picture can be output with the shipout function (see [shipout], page 46).
If you wish to draw PostScript objects on top of labels (or verbatim tex commands;
see [tex], page 50), the layer command may be used to start a new PostScript/LaTeX
layer:
void layer(picture pic=currentpicture);
The layer function gives one full control over the order in which objects are drawn.
Layers are drawn sequentially, with the most recent layer appearing on top. Within each
layer, labels, images, and verbatim tex commands are always drawn after the PostScript
objects in that layer.
While some of these drawing commands take many options, they all have sensible default
values (for example, the picture argument defaults to currentpicture).
4.1 draw
void draw(picture pic=currentpicture, Label L="", path g,
align align=NoAlign, pen p=currentpen,
arrowbar arrow=None, arrowbar bar=None, margin margin=NoMargin,
Label legend="", marker marker=nomarker);
Draw the path g on the picture pic using pen p for drawing, with optional drawing attributes
(Label L, explicit label alignment align, arrows and bars arrow and bar, margins margin,
legend, and markers marker). Only one parameter, the path, is required. For convenience,
the arguments arrow and bar may be specified in either order. The argument legend is a
Label to use in constructing an optional legend entry.
Bars are useful for indicating dimensions. The possible values of bar are None, BeginBar,
EndBar (or equivalently Bar), and Bars (which draws a bar at both ends of the path). Each
of these bar specifiers (except for None) will accept an optional real argument that denotes
the length of the bar in PostScript coordinates. The default bar length is barsize(pen).
The possible values of arrow are None, Blank (which draws no arrows or path),
BeginArrow, MidArrow, EndArrow (or equivalently Arrow), and Arrows (which draws an
arrow at both ends of the path). All of the arrow specifiers except for None and Blank may
be given the optional arguments arrowhead arrowhead (one of the predefined arrowhead
styles DefaultHead, SimpleHead, HookHead, TeXHead), real size (arrowhead size in
PostScript coordinates), real angle (arrowhead angle in degrees), filltype filltype
(one of FillDraw, Fill, NoFill, UnFill, Draw) and (except for MidArrow and Arrows) a
relative real position along the path (an arctime) where the tip of the arrow should be
placed. The default arrowhead size when drawn with a pen p is arrowsize(p). There are
also arrow versions with slightly modified default values of size and angle suitable for
Chapter 4: Drawing commands 16
filltype filltype=Fill);
If the variable Label is given as the Label argument to the second routine, the format
argument will be used to format a string based on the dot location (here defaultformat
is "$%.4g$"). The third routine draws a dot at every point of a pair array z. One can also
draw a dot at every node of a path:
void dot(picture pic=currentpicture, Label[] L=new Label[],
path g, align align=RightSide, string format=defaultformat,
pen p=currentpen, filltype filltype=Fill);
See [pathmarkers], page 103 and Section 7.9 [markers], page 87 for more general methods
for marking path nodes.
To draw a fixed-sized object (in PostScript coordinates) about the user coordinate
origin, use the routine
void draw(pair origin, picture pic=currentpicture, Label L="", path g,
align align=NoAlign, pen p=currentpen, arrowbar arrow=None,
arrowbar bar=None, margin margin=NoMargin, Label legend="",
marker marker=nomarker);
4.2 fill
void fill(picture pic=currentpicture, path g, pen p=currentpen);
Fill the interior region bounded by the cyclic path g on the picture pic, using the pen p.
There is also a convenient filldraw command, which fills the path and then draws in
the boundary. One can specify separate pens for each operation:
void filldraw(picture pic=currentpicture, path g, pen fillpen=currentpen,
pen drawpen=currentpen);
This fixed-size version of fill allows one to fill an object described in PostScript
coordinates about the user coordinate origin:
void fill(pair origin, picture pic=currentpicture, path g, pen p=currentpen);
This is just a convenient abbreviation for the commands:
picture opic;
fill(opic,g,p);
add(pic,opic,origin);
The routine
void filloutside(picture pic=currentpicture, path g, pen p=currentpen);
fills the region exterior to the path g, out to the current boundary of picture pic.
Lattice gradient shading varying smoothly over a two-dimensional array of pens p, using
fill rule fillrule, can be produced with
void latticeshade(picture pic=currentpicture, path g, bool stroke=false,
pen fillrule=currentpen, pen[][] p)
If stroke=true, the region filled is the same as the region that would be drawn by
draw(pic,g,fillrule+zerowinding); in this case the path g need not be cyclic. The
pens in p must belong to the same color space. One can use the functions rgb(pen)
or cmyk(pen) to promote pens to a higher color space, as illustrated in the example file
latticeshading.asy.
Chapter 4: Drawing commands 18
Axial gradient shading varying smoothly from pena to penb in the direction of the line
segment a--b can be achieved with
void axialshade(picture pic=currentpicture, path g, bool stroke=false,
pen pena, pair a,
pen penb, pair b);
Radial gradient shading varying smoothly from pena on the circle with center a and
radius ra to penb on the circle with center b and radius rb is similar:
void radialshade(picture pic=currentpicture, path g, bool stroke=false,
pen pena, pair a, real ra,
pen penb, pair b, real rb);
Illustrations of radial shading are provided in the example files shade.asy, ring.asy, and
shadestroke.asy.
Gouraud shading using fill rule fillrule and the vertex colors in the pen array p on a
triangular lattice defined by the vertices z and edge flags edges is implemented with
void gouraudshade(picture pic=currentpicture, path g, bool stroke=false,
pen fillrule=currentpen, pen[] p, pair[] z,
int[] edges);
void gouraudshade(picture pic=currentpicture, path g, bool stroke=false,
pen fillrule=currentpen, pen[] p, int[] edges);
In the second form, the elements of z are taken to be successive nodes of path g. The pens
in p must belong to the same color space. Illustrations of Gouraud shading are provided
in the example file Gouraud.asy and in the solid geometry module solids.asy. The edge
flags used in Gouraud shading are documented here:
http://partners.adobe.com/public/developer/en/ps/sdk/TN5600.SmoothShading.pdf.
Tensor product shading using fill rule fillrule on patches bounded by the n cyclic
paths of length 4 in path array b, using the vertex colors specified in the n × 4 pen array p
and internal control points in the n × 4 array z, is implemented with
void tensorshade(picture pic=currentpicture, path g, bool stroke=false,
pen fillrule=currentpen, pen[][] p, path[] b=g,
pair[][] z=new pair[][]);
If the array z is empty, Coons shading, in which the color control points are calculated
automatically, is used. The pens in p must belong to the same color space. A simpler
interface for the case of a single patch (n = 1) is also available:
void tensorshade(picture pic=currentpicture, path g, bool stroke=false,
pen fillrule=currentpen, pen[] p, path b=g,
pair[] z=new pair[]);
One can also smoothly shade the regions between consecutive paths of a sequence using
a given array of pens:
void draw(picture pic=currentpicture, path[] g, pen[] p);
Illustrations of tensor product and Coons shading are provided in the example files
tensor.asy, Coons.asy, BezierSurface.asy, and rainbow.asy.
More general shading possibilities are available with the pdflatex, context, and pdftex
TEX engines: the routine
Chapter 4: Drawing commands 19
4.3 clip
void clip(picture pic=currentpicture, path g, stroke=false,
pen fillrule=currentpen);
Clip the current contents of picture pic to the region bounded by the path g, using fill rule
fillrule (see [fillrule], page 40). If stroke=true, the clipped portion is the same as the
region that would be drawn with draw(pic,g,fillrule+zerowinding); in this case the
path g need not be cyclic. For an illustration of picture clipping, see the first example in
Chapter 6 [LaTeX usage], page 81.
4.4 label
void label(picture pic=currentpicture, Label L, pair position,
align align=NoAlign, pen p=nullpen, filltype filltype=NoFill)
Draw Label L on picture pic using pen p. If align is NoAlign, the label will be centered
at user coordinate position; otherwise it will be aligned in the direction of align and
displaced from position by the PostScript offset align*labelmargin(p). The constant
Align can be used to align the bottom-left corner of the label at position. If p is nullpen,
the pen specified within the Label, which defaults to currentpen, will be used. The Label
L can either be a string or the structure obtained by calling one of the functions
Label Label(string s="", pair position, align align=NoAlign,
pen p=nullpen, embed embed=Rotate, filltype filltype=NoFill);
Label Label(string s="", align align=NoAlign,
pen p=nullpen, embed embed=Rotate, filltype filltype=NoFill);
Label Label(Label L, pair position, align align=NoAlign,
pen p=nullpen, embed embed=L.embed, filltype filltype=NoFill);
Label Label(Label L, align align=NoAlign,
pen p=nullpen, embed embed=L.embed, filltype filltype=NoFill);
The text of a Label can be scaled, slanted, rotated, or shifted by multiplying
it on the left by an affine transform (see Section 5.4 [Transforms], page 44). For
example, rotate(45)*xscale(2)*L first scales L in the x direction and then rotates it
counterclockwise by 45 degrees. The final position of a Label can also be shifted by a
PostScript coordinate translation: shift(10,0)*L. The embed argument determines
how the Label should transform with the embedding picture:
Shift only shift with embedding picture;
Chapter 4: Drawing commands 20
Asymptote
The Vector Graphics Language
Andy Hammerlindl, John Bowman, and Tom Prince
http://asymptote.sourceforge.net
symptote
Chapter 4: Drawing commands 22
size(11.7cm,11.7cm);
asy(nativeformat(),"logo");
fill(unitcircle^^(scale(2/11.7)*unitcircle),
evenodd+rgb(124/255,205/255,124/255));
label(scale(1.1)*minipage(
"\centering\scriptsize \textbf{\LARGE {\tt Asymptote}\\
\smallskip
\small The Vector Graphics Language}\\
\smallskip
\textsc{Andy Hammerlindl, John Bowman, and Tom Prince}
http://asymptote.sourceforge.net\\
",8cm),(0,0.6));
label(graphic("logo."+nativeformat(),"height=7cm"),(0,-0.22));
clip(unitcircle^^(scale(2/11.7)*unitcircle),evenodd);
Chapter 5: Programming 23
5 Programming
Here is a short introductory example to the Asymptote programming language that
highlights the similarity of its control structures with those of C, C++, and Java:
// This is a comment.
Asymptote supports while, do, break, and continue statements just as in C/C++. It
also supports the Java-style shorthand for iterating over all elements of an array:
// Iterate over an array
int[] array={1,1,2,3,5};
for(int k : array) {
write(k);
}
In addition, it supports many features beyond the ones found in those languages.
bool3 an extended boolean type that can take on the values true, default, or false.
A bool3 type can be cast to or from a bool. The default initializer for bool3 is
default.
int an integer type; if no initializer is given, the implicit value 0 is assumed. The
minimum allowed value of an integer is intMin and the maximum value is
intMax.
real a real number; this should be set to the highest-precision native floating-point
type on the architecture. The implicit initializer for reals is 0.0. Real numbers
have precision realEpsilon, with realDigits significant digits. The smallest
positive real number is realMin and the largest positive real number is realMax.
pair complex number, that is, an ordered pair of real components (x,y). The real
and imaginary parts of a pair z can read as z.x and z.y. We say that x and y
are virtual members of the data element pair; they cannot be directly modified,
however. The implicit initializer for pairs is (0.0,0.0).
There are a number of ways to take the complex conjugate of a pair:
pair z=(3,4);
z=(z.x,-z.y);
z=z.x-I*z.y;
z=conj(z);
Here I is the pair (0,1). A number of built-in functions are defined for pairs:
pair conj(pair z)
returns the conjugate of z;
real length(pair z)
returns the complex modulus |z| of its argument z. For example,
pair z=(3,4);
length(z);
returns the result 5. A synonym for length(pair) is abs(pair);
real angle(pair z, bool warn=true)
returns the angle of z in radians in the interval [-pi,pi] or 0 if warn
is false and z=(0,0) (rather than producing an error);
real degrees(pair z, bool warn=true)
returns the angle of z in degrees in the interval [0,360) or 0 if warn
is false and z=(0,0) (rather than producing an error);
pair unit(pair z)
returns a unit vector in the direction of the pair z;
pair expi(real angle)
returns a unit vector in the direction angle measured in radians;
pair dir(real degrees)
returns a unit vector in the direction degrees measured in degrees;
real xpart(pair z)
returns z.x;
Chapter 5: Programming 25
real ypart(pair z)
returns z.y;
pair realmult(pair z, pair w)
returns the element-by-element product (z.x*w.x,z.y*w.y);
real dot(pair z, pair w)
returns the dot product z.x*w.x+z.y*w.y;
pair minbound(pair z, pair w)
returns (min(z.x,w.x),min(z.y,w.y));
pair maxbound(pair z, pair w)
returns (max(z.x,w.x),max(z.y,w.y)).
triple an ordered triple of real components (x,y,z) used for three-dimensional
drawings. The respective components of a triple v can read as v.x, v.y, and
v.z. The implicit initializer for triples is (0.0,0.0,0.0).
Here are the built-in functions for triples:
real length(triple v)
returns the length |v| of the vector v. A synonym for
length(triple) is abs(triple);
real polar(triple v, bool warn=true)
returns the colatitude of v measured from the z axis in radians or
0 if warn is false and v=O (rather than producing an error);
real azimuth(triple v, bool warn=true)
returns the longitude of v measured from the x axis in radians or 0
if warn is false and v.x=v.y=0 (rather than producing an error);
real colatitude(triple v, bool warn=true)
returns the colatitude of v measured from the z axis in degrees or
0 if warn is false and v=O (rather than producing an error);
real latitude(triple v, bool warn=true)
returns the latitude of v measured from the xy plane in degrees or
0 if warn is false and v=O (rather than producing an error);
real longitude(triple v, bool warn=true)
returns the longitude of v measured from the x axis in degrees or 0
if warn is false and v.x=v.y=0 (rather than producing an error);
triple unit(triple v)
returns a unit triple in the direction of the triple v;
triple expi(real polar, real azimuth)
returns a unit triple in the direction (polar,azimuth) measured
in radians;
triple dir(real colatitude, real longitude)
returns a unit triple in the direction (colatitude,longitude)
measured in degrees;
Chapter 5: Programming 26
real xpart(triple v)
returns v.x;
real ypart(triple v)
returns v.y;
real zpart(triple v)
returns v.z;
real dot(triple u, triple v)
returns the dot product u.x*v.x+u.y*v.y+u.z*v.z;
triple cross(triple u, triple v)
returns the cross product
(u.y*v.z-u.z*v.y,u.z*v.x-u.x*v.z,u.x*v.y-v.x*u.y);
triple minbound(triple u, triple v)
returns (min(u.x,v.x),min(u.y,v.y),min(u.z,v.z));
triple maxbound(triple u, triple v)
returns (max(u.x,v.x),max(u.y,v.y),max(u.z,v.z)).
string a character string, implemented using the STL string class.
Strings delimited by double quotes (") are subject to the following mappings
to allow the use of double quotes in TEX (e.g. for using the babel package, see
Section 7.22 [babel], page 92):
• \" maps to "
• \\ maps to \\
Strings delimited by single quotes (’) have the same mappings as character
strings in ANSI C:
• \’ maps to ’
• \" maps to "
• \? maps to ?
• \\ maps to backslash
• \a maps to alert
• \b maps to backspace
• \f maps to form feed
• \n maps to newline
• \r maps to carriage return
• \t maps to tab
• \v maps to vertical tab
• \0-\377 map to corresponding octal byte
• \x0-\xFF map to corresponding hexadecimal byte
The implicit initializer for strings is the empty string "". Strings may be
concatenated with the + operator. In the following string functions, position 0
denotes the start of the string:
Chapter 5: Programming 27
int length(string s)
returns the length of the string s;
int find(string s, string t, int pos=0)
returns the position of the first occurrence of string t in string s at
or after position pos, or -1 if t is not a substring of s;
int rfind(string s, string t, int pos=-1)
returns the position of the last occurrence of string t in string s at
or before position pos (if pos=-1, at the end of the string s), or -1
if t is not a substring of s;
string insert(string s, int pos, string t)
returns the string formed by inserting string t at position pos in s;
string erase(string s, int pos, int n)
returns the string formed by erasing the string of length n (if n=-1,
to the end of the string s) at position pos in s;
string substr(string s, int pos, int n=-1)
returns the substring of s starting at position pos and of length n
(if n=-1, until the end of the string s);
string reverse(string s)
returns the string formed by reversing string s;
string replace(string s, string before, string after)
returns a string with all occurrences of the string before in the
string s changed to the string after;
string replace(string s, string[][] table)
returns a string constructed by translating in string s all
occurrences of the string before in an array table of string pairs
{before,after} to the corresponding string after;
string[] split(string s, string delimiter=" ")
returns an array of strings obtained by splitting s into substrings
delimited by delimiter;
string format(string s, int n)
returns a string containing n formatted according to the C-style
format string s using the current locale;
string format(string s=defaultformat, real x, string locale="")
returns a string containing x formatted according to the C-style
format string s using locale locale (or the current locale if an
empty string is specified), following the behaviour of the C func-
tion fprintf), except that only one data field is allowed, trailing
zeros are removed by default (unless # is specified), and (if the
format string specifies math mode) TEX is used to typeset scientific
notation;
int hex(string s);
casts a hexidecimal string s to an integer.
Chapter 5: Programming 28
void beep()
produces a beep on the console;
As in C/C++, complicated types may be abbreviated with typedef (see the example in
Section 5.11 [Functions], page 61).
}
This example illustrates the use of all five guide connectors discussed in
Chapter 3 [Tutorial], page 9:
size(300,0);
pair[] z=new pair[10];
path p=z[0]..z[1]---z[2]::{up}z[3]
&z[3]..z[4]--z[5]::{up}z[6]
&z[6]::z[7]---z[8]..{up}z[9];
draw(p,grey+linewidth(4mm));
dot(z);
real[] mintimes(path p)
returns an array of length 2 containing times at which path p
reaches its minimal horizontal and vertical extents, respectively.
real[] maxtimes(path p)
returns an array of length 2 containing the times at which path p
reaches its maximal horizontal and vertical extents, respectively.
pair intersectionpoint(path p, path q, real fuzz=-1);
returns the intersection point point(p,intersect(p,q,fuzz)[0]).
pair[] intersectionpoints(path p, path q, real fuzz=-1);
returns an array containing all intersection points of the paths p
and q.
pair extension(pair P, pair Q, pair p, pair q);
returns the intersection point of the extensions of the line segments
P--Q and p--q, or if the lines are parallel, (infinity,infinity).
slice cut(path p, path knife, int n);
returns the portions of path p before and after the nth intersection
of p with path knife as a structure slice (if no intersection exist is
found, the entire path is considered to be ‘before’ the intersection):
struct slice {
path before,after;
}
The argument n is treated as modulo the number of intersections.
slice firstcut(path p, path knife);
equivalent to cut(p,knife,0); Note that firstcut.after plays
the role of the MetaPost cutbefore command.
slice lastcut(path p, path knife);
equivalent to cut(p,knife,-1); Note that lastcut.before plays
the role of the MetaPost cutafter command.
path buildcycle(... path[] p);
This returns the path surrounding a region bounded by a list of two
or more consecutively intersecting paths, following the behaviour
of the MetaPost buildcycle command.
pair min(path p);
returns the pair (left,bottom) for the path bounding box of path p.
pair max(path p);
returns the pair (right,top) for the path bounding box of path p.
int windingnumber(path p, pair z);
returns the winding number of the cyclic path p relative to the point
z. The winding number is positive if the path encircles z in the
counterclockwise direction. If z lies on p the constant undefined
(defined to be the largest odd integer) is returned.
Chapter 5: Programming 34
int n=30;
real a=1.5;
real width=2a/n;
guide hat;
path solved;
draw(hat);
dot(hat,red);
draw(solved,dashed);
5.3 Pens
In Asymptote, pens provide a context for the four basic drawing commands (see Chapter 4
[Drawing commands], page 15). They are used to specify the following drawing attributes:
color, line type, line width, line cap, line join, fill rule, text alignment, font, font size,
pattern, overwrite mode, and calligraphic transforms on the pen nib. The default pen used
by the drawing routines is called currentpen. This provides the same functionality as the
MetaPost command pickup. The implicit initializer for pens is defaultpen.
Pens may be added together with the nonassociative binary operator +. This will add
the colors of the two pens. All other non-default attributes of the rightmost pen will
override those of the leftmost pen. Thus, one can obtain a yellow dashed pen by saying
dashed+red+green or red+green+dashed or red+dashed+green. The binary operator *
can be used to scale the color of a pen by a real number, until it saturates with one or more
color components equal to 1.
• Colors are specified using one of the following colorspaces:
pen gray(real g);
This produces a grayscale color, where the intensity g lies in the interval
[0,1], with 0.0 denoting black and 1.0 denoting white.
Chapter 5: Programming 37
pen invisible;
This special pen writes in invisible ink, but adjusts the bounding box
as if something had been drawn (like the \phantom command in TEX).
The function bool invisible(pen) can be used to test whether a pen is
invisible.
The default color is black; this may be changed with the routine defaultpen(pen).
The function colorspace(pen p) returns the colorspace of pen p as a string ("gray",
"rgb", "cmyk", or "").
The function real[] colors(pen) returns the color components of a pen. The
functions pen gray(pen), pen rgb(pen), and pen cmyk(pen) return new pens
obtained by converting their arguments to the respective color spaces. The function
colorless(pen=currentpen) returns a copy of its argument with the color attributes
stripped (to avoid color mixing).
A 6-character RGB hexidecimal string can be converted to a pen with the routine
Various shades and mixtures of the grayscale primary colors black and white, RGB
primary colors red, green, and blue, and RGB secondary colors cyan, magenta,
and yellow are defined as named colors, along with the CMYK primary colors Cyan,
Magenta, Yellow, and Black, in the module plain:
Chapter 5: Programming 38
begin. The first number specifies how far (if scale is true, in units of the pen line
width; otherwise in PostScript units) to draw with the pen on, the second number
specifies how far to draw with the pen off, and so on. If adjust is true, these spacings
are automatically adjusted by Asymptote to fit the arclength of the path. Here are the
predefined line types:
pen solid=linetype("");
pen dotted=linetype("0 4");
pen dashed=linetype("8 8");
pen longdashed=linetype("24 8");
pen dashdotted=linetype("8 8 0 8");
pen longdashdotted=linetype("24 8 0 8");
pen Dotted=dotted+1.0;
pen Dotted(pen p=currentpen) {return dotted+2*linewidth(p);}
The default line type is solid; this may be changed with defaultpen(pen). The line
type of a pen is returned by int linetype(pen p=currentpen).
• The pen line width is specified in PostScript units with pen linewidth(real). The
default line width is 0.5 bp; this value may be changed with defaultpen(pen). The line
width of a pen is returned by real linewidth(pen p=currentpen). For convenience,
in the module plain we define
static void defaultpen(real w) {defaultpen(linewidth(w));}
static pen operator +(pen p, real w) {return p+linewidth(w);}
static pen operator +(real w, pen p) {return linewidth(w)+p;}
so that one may set the line width like this:
defaultpen(2);
pen p=red+0.5;
• A pen with a specific PostScript line cap is returned on calling linecap with an
integer argument:
pen squarecap=linecap(0);
pen roundcap=linecap(1);
pen extendcap=linecap(2);
The default line cap, roundcap, may be changed with defaultpen(pen). The line cap
of a pen is returned by int linecap(pen p=currentpen).
• A pen with a specific PostScript join style is returned on calling linejoin with an
integer argument:
pen miterjoin=linejoin(0);
pen roundjoin=linejoin(1);
pen beveljoin=linejoin(2);
The default join style, roundjoin, may be changed with defaultpen(pen).The join
style of a pen is returned by int linejoin(pen p=currentpen).
Chapter 5: Programming 40
add("tile",tile());
add("filledtilewithmargin",tile(6mm,4mm,red,Fill),(1mm,1mm),(1mm,1mm));
add("checker",checker());
add("brick",brick());
real s=2.5;
filldraw(unitcircle,pattern("tile"));
Chapter 5: Programming 42
filldraw(shift(s,0)*unitcircle,pattern("filledtilewithmargin"));
filldraw(shift(2s,0)*unitcircle,pattern("checker"));
filldraw(shift(3s,0)*unitcircle,pattern("brick"));
Hatch patterns can be generated with the routines picture hatch(real H=5mm,
pair dir=NE, pen p=currentpen), picture crosshatch(real H=5mm, pen
p=currentpen):
size(0,100);
import patterns;
add("hatch",hatch());
add("hatchback",hatch(NW));
add("crosshatch",crosshatch(3mm));
real s=1.25;
filldraw(unitsquare,pattern("hatch"));
filldraw(shift(s,0)*unitsquare,pattern("hatchback"));
filldraw(shift(2s,0)*unitsquare,pattern("crosshatch"));
You may need to turn off aliasing in your PostScript viewer for patterns to appear
correctly. Custom patterns can easily be constructed, following the examples in
patterns.asy. The tiled pattern can even incorporate shading (see [gradient shading],
page 17), as illustrated in this example (not included in the manual because not all
printers support PostScript 3):
size(0,100);
import patterns;
real d=4mm;
picture tiling;
path square=scale(d)*unitsquare;
axialshade(tiling,square,white,(0,0),black,(d,d));
Chapter 5: Programming 43
fill(tiling,shift(d,d)*square,blue);
add("shadedtiling",tiling);
filldraw(unitcircle,pattern("shadedtiling"));
• One can specify a custom pen nib as an arbitrary polygonal path with pen
makepen(path); this path represents the mark to be drawn for paths containing a
single point. This pen nib path can be recovered from a pen with path nib(pen).
Unlike in MetaPost, the path need not be convex:
size(200);
pen convex=makepen(scale(10)*polygon(8))+grey;
draw((1,0.4),convex);
draw((0,0)---(1,1)..(2,0)--cycle,convex);
pen nonconvex=scale(10)*
makepen((0,0)--(0.25,-1)--(0.5,0.25)--(1,0)--(0.5,1.25)--cycle)+red;
draw((0.5,-1.5),nonconvex);
draw((0,-1.5)..(1,-0.5)..(2,-1.5),nonconvex);
The value nullpath represents a circular pen nib (the default); an elliptical pen can
be achieved simply by multiplying the pen by a transform: yscale(2)*currentpen.
• One can prevent labels from overwriting one another by using the pen attribute
overwrite, which takes a single argument:
Allow Allow labels to overwrite one another. This is the default behaviour (unless
overridden with defaultpen(pen).
Suppress Suppress, with a warning, each label that would overwrite another label.
SuppressQuiet
Suppress, without warning, each label that would overwrite another label.
Chapter 5: Programming 44
Move Move a label that would overwrite another out of the way and issue
a warning. As this adjustment is during the final output phase (in
PostScript coordinates) it could result in a larger figure than requested.
MoveQuiet
Move a label that would overwrite another out of the way, without
warning. As this adjustment is during the final output phase (in
PostScript coordinates) it could result in a larger figure than requested.
The routine defaultpen() returns the current default pen attributes. Calling the routine
resetdefaultpen() resets all pen default attributes to their initial values.
5.4 Transforms
Asymptote makes extensive use of affine transforms. A pair (x,y) is transformed by the
transform t=(t.x,t.y,t.xx,t.xy,t.yx,t.yy) to (x’,y’), where
x’ = t.x + t.xx * x + t.xy * y
y’ = t.y + t.yx * x + t.yy * y
This is equivalent to the PostScript transformation [t.xx t.yx t.xy t.yy t.x t.y].
Transforms can be applied to pairs, guides, paths, pens, strings, transforms, frames, and
pictures by multiplication (via the binary operator *) on the left (see [circle], page 29 for an
example). Transforms can be composed with one another and inverted with the function
transform inverse(transform t); they can also be raised to any integer power with the
^ operator.
The built-in transforms are:
transform identity();
the identity transform;
transform shift(pair z);
translates by the pair z;
transform shift(real x, real y);
translates by the pair (x,y);
transform xscale(real x);
scales by x in the x direction;
transform yscale(real y);
scales by y in the y direction;
transform scale(real s);
scale by s in both x and y directions;
transform scale(real x, real y);
scale by x in the x direction and by y in the y direction;
transform slant(real s);
maps (x,y) –> (x+s*y,y);
transform rotate(real angle, pair z=(0,0));
rotates by angle in degrees about z;
Chapter 5: Programming 45
To rotate the page by −90 degrees, use the orientation Seascape. The
orientation UpsideDown rotates the page by 180 degrees.
A picture pic can be explicitly fit to a frame by calling
frame pic.fit(real xsize=pic.xsize, real ysize=pic.ysize,
bool keepAspect=pic.keepAspect);
The default size and aspect ratio settings are those given to the size command
(which default to 0, 0, and true, respectively). The transformation that would
currently be used to fit a picture pic to a frame is returned by the member
function pic.calculateTransform().
In certain cases (e.g. 2D graphs) where only an approximate size estimate for
pic is available, the picture fitting routine
frame pic.scale(real xsize=this.xsize, real ysize=this.ysize,
bool keepAspect=this.keepAspect);
(which scales the resulting frame, including labels and fixed-size objects) will
enforce perfect compliance with the requested size specification, but should not
normally be required.
To draw a bounding box with margins around a picture, fit the picture to a
frame using the function
frame bbox(picture pic=currentpicture, real xmargin=0,
real ymargin=xmargin, pen p=currentpen,
filltype filltype=NoFill);
Here filltype specifies one of the following fill types:
FillDraw Fill the interior and draw the boundary.
FillDraw(real xmargin=0, real ymargin=xmargin, pen fillpen=nullpen,
pen drawpen=nullpen); If fillpen is nullpen, fill with the
drawing pen; otherwise fill with pen fillpen. If drawpen is
nullpen, draw the boundary with fillpen; otherwise with
drawpen. An optional margin of xmargin and ymargin can be
specified.
Fill Fill the interior.
Fill(real xmargin=0, real ymargin=xmargin, pen p=nullpen)
If p is nullpen, fill with the drawing pen; otherwise fill with pen p.
An optional margin of xmargin and ymargin can be specified.
NoFill Do not fill.
Draw Draw only the boundary.
Draw(real xmargin=0, real ymargin=xmargin, pen p=nullpen)
If p is nullpen, draw the boundary with the drawing pen; otherwise
draw with pen p. An optional margin of xmargin and ymargin can
be specified.
UnFill Clip the region.
UnFill(real xmargin=0, real ymargin=xmargin)
Clip the region and surrounding margins xmargin and ymargin.
Chapter 5: Programming 48
The optional align argument in the last three forms specifies a direction to
use for aligning the frame, in a manner analogous to the align argument of
label (see Section 4.4 [label], page 19). However, one key difference is that
when align is not specified, labels are centered, whereas frames and pictures
are aligned so that their origin is at position. Illustrations of frame alignment
can be found in the examples [errorbars], page 104 and [image], page 123. If
you want to align three or more subpictures, group them two at a time:
picture pic1;
real size=50;
size(pic1,size);
fill(pic1,(0,0)--(50,100)--(100,0)--cycle,red);
picture pic2;
size(pic2,size);
fill(pic2,unitcircle,green);
picture pic3;
size(pic3,size);
fill(pic3,unitsquare,blue);
picture pic;
add(pic,pic1.fit(),(0,0),N);
add(pic,pic2.fit(),(0,0),10S);
add(pic.fit(),(0,0),N);
add(pic3.fit(),(0,0),10S);
Chapter 5: Programming 50
Alternatively, one can use attach to automatically increase the size of picture
dest to accommodate adding a frame src about the user coordinate position:
void attach(picture dest=currentpicture, frame src,
pair position=0, bool group=true,
filltype filltype=NoFill, bool above=true);
void attach(picture dest=currentpicture, frame src,
pair position, pair align, bool group=true,
filltype filltype=NoFill, bool above=true);
To erase the contents of a picture (but not the size specification), use the
function
void erase(picture pic=currentpicture);
To save a snapshot of currentpicture, currentpen, and currentprojection,
use the function save().
To restore a snapshot of currentpicture, currentpen, and
currentprojection, use the function restore().
Many further examples of picture and frame operations are provided in the base
module plain.
It is possible to insert verbatim PostScript commands in a picture with one
of the routines
void postscript(picture pic=currentpicture, string s);
void postscript(picture pic=currentpicture, string s, pair min,
pair max)
Here min and max can be used to specify explicit bounds associated with the
resulting PostScript code.
Verbatim TEX commands can be inserted in the intermediate LaTeX output file
with one of the functions
void tex(picture pic=currentpicture, string s);
void tex(picture pic=currentpicture, string s, pair min, pair max)
Here min and max can be used to specify explicit bounds associated with the
resulting TEX code.
To issue a global TEX command (such as a TEX macro definition) in the TEX
preamble (valid for the remainder of the top-level module) use:
Chapter 5: Programming 51
5.6 Files
Asymptote can read and write text files (including comma-separated value) files and
portable XDR (External Data Representation) binary files.
An input file must first be opened with input(string name, bool check=true, string
comment="#"); reading is then done by assignment:
file fin=input("test.txt");
real a=fin;
If the optional boolean argument check is false, no check will be made that the file
exists. If the file does not exist or is not readable, the function bool error(file) will
return true. The first character of the string comment specifies a comment character. If
this character is encountered in a data file, the remainder of the line is ignored. When
reading strings, a comment character followed immediately by another comment character
is treated as a single literal comment character.
If the -globalwrite (or -nosafe) option is enabled, one can change the current working
directory to the contents of the string s with the function string cd(string s), which
returns the new working directory. If string s is empty, the path is reset to the value it
had at program startup.
When reading pairs, the enclosing parenthesis are optional. Strings are also read by
assignment, by reading characters up to but not including a newline. In addition, Asymptote
provides the function string getc(file) to read the next character (treating the comment
character as an ordinary character) and return it as a string.
A file named name can be open for output with
file output(string name, bool update=false);
If update=false, any existing data in the file will be erased and only write operations can
be used on the file. If update=true, any existing data will be preserved, the position will be
set to the end-of-file, and both reading and writing operations will be enabled. For security
reasons, writing to files in directories other than the current directory is allowed only if the
-globalwrite (or -nosafe) command-line option is specified.
There are two special files: stdin, which reads from the keyboard, and stdout, which
writes to the terminal. The implicit initializer for files is null.
Data of a built-in type T can be written to an output file by calling one of the functions
Chapter 5: Programming 52
one less than the current number of display lines). The default value, settings.scroll=0,
specifies continuous scrolling.
The routines
string getstring(string name="", string default="", string prompt="",
bool store=true);
int getint(string name="", int default=0, string prompt="",
bool store=true);
real getreal(string name="", real default=0, string prompt="",
bool store=true);
pair getpair(string name="", pair default=0, string prompt="",
bool store=true);
triple gettriple(string name="", triple default=(0,0,0), string prompt="",
bool store=true);
defined in the module plain may be used to prompt for a value from stdin using the GNU
readline library. If store=true, the history of values for name is stored in the file ".asy_
history_"+name (see [history], page 157). The most recent value in the history will be
used to provide a default value for subsequent runs. The default value (initially default)
is displayed after prompt. These functions are based on the internal routines
string readline(string prompt="", string name="", bool tabcompletion=false);
void saveline(string name, string value, bool store=true);
Here, readline prompts the user with the default value formatted according to prompt,
while saveline is used to save the string value in a local history named name, optionally
storing the local history in a file ".asy_history_"+name.
The routine history(string name, int n=1) can be used to look up the n most recent
values (or all values up to historylines if n=0) entered for string name. The routine
history(int n=0) returns the interactive history. For example,
write(output("transcript.asy"),history());
outputs the interactive history to the file transcript.asy.
The function int delete(string s) deletes the file named by the string s. Unless the
-globalwrite (or -nosafe) option is enabled, the file must reside in the current directory.
The function int rename(string from, string to) may be used to rename file from to
file to. Unless the -globalwrite (or -nosafe) option is enabled, this operation is restricted
to the current directory. The functions
int convert(string args="", string file="", string format="");
int animate(string args="", string file="", string format="");
call the ImageMagick commands convert and animate, respectively, with the arguments
args and the file name constructed from the strings file and format. If the setting safe is
false, then the functions int system(string s) and int system(string[] s) can be used
to call the arbitrary system command s.
A variable is not added to the namespace until after the initializer is evaluated, so for
example, in
int x=2;
int x=5*x;
the x in the initializer on the second line refers to the variable x declared on the first line.
The second line, then, declares a variable x shadowing the original x and initializes it to
the value 10.
Variables of most types can be declared without an explicit initializer and they will be
initialized by the default initializer of that type:
• Variables of the numeric types int, real, and pair are all initialized to zero; variables
of type triple are initialized to O=(0,0,0).
• boolean variables are initialized to false.
• string variables are initialized to the empty string.
• transform variables are initialized to the identity transformation.
• path and guide variables are initialized to nullpath.
• pen variables are initialized to the default pen.
• frame and picture variables are initialized to empty frames and pictures, respectively.
• file variables are initialized to null.
The default initializers for user-defined array, structure, and function types are explained
in their respective sections. Some types, such as code, do not have default initializers. When
a variable of such a type is introduced, the user must initialize it by explicitly giving it a
value.
The default initializer for any type T can be redeclared by defining the function T
operator init(). For instance, int variables are usually initialized to zero, but in
int operator init() {
return 3;
}
int y;
the variable y is initialized to 3. This example was given for illustrative purposes; redeclaring
the initializers of built-in types is not recommended. Typically, operator init is used to
define sensible defaults for user-defined types.
5.8 Structures
Users may also define their own data types as structures, along with user-defined operators,
much as in C++. By default, structure members are public (may be read and modified
anywhere in the code), but may be optionally declared restricted (readable anywhere
but writeable only inside the structure where they are defined) or private (readable and
writable only inside the structure). In a structure definition, the keyword this can be used
as an expression to refer to the enclosing structure. Any code at the top-level scope within
the structure is executed on initialization.
Variables hold references to structures. That is, in the example:
Chapter 5: Programming 55
struct T {
int x;
}
T foo=new T;
T bar=foo;
bar.x=5;
The variable foo holds a reference to an instance of the structure T. When bar is
assigned the value of foo, it too now holds a reference to the same instance as foo does.
The assignment bar.x=5 changes the value of the field x in that instance, so that foo.x
will also be equal to 5.
The expression new T creates a new instance of the structure T and returns a reference
to that instance. In creating the new instance, any code in the body of the record definition
is executed. For example:
int Tcount=0;
struct T {
int x;
++Tcount;
}
T foo=new T;
Here, the expression new T will produce a new instance of the class, but will also cause
Tcount to be incremented, so that it keeps track of the number of instances produced.
The expression null can be cast to any structure type to yield a null reference, a reference
that does not actually refer to any instance of the structure. Trying to use a field of a null
reference will cause an error.
The function bool alias(T,T) checks to see if two structure references refer to the same
instance of the structure (or both to null). For example, in the example code at the start
of the section, alias(foo,bar) would return true, but alias(foo,new T) would return
false, as new T creates a new instance of the structure T. The boolean operators == and !=
are by default equivalent to alias and !alias respectively, but may be overwritten for a
particular type (for example, to do a deep comparison).
After the definition of a structure T, a variable of type T is initialized to a new instance
(new T) by default. During the definition of the structure, however, variables of type T
are initialized to null by default. This special behaviour is to avoid infinite recursion of
creating new instances in code such as
struct tree {
int value;
tree left;
tree right;
}
Here is a simple example that illustrates the use of structures:
struct S {
real a=1;
real f(real a) {return a+this.a;}
Chapter 5: Programming 56
write(s.f(2)); // Outputs 3
write((s+s).f(0)); // Outputs 2
It is often convenient to have functions that construct new instances of a structure. Say
we have a Person structure:
struct Person {
string firstname;
string lastname;
}
immediately after the structure definition, then the constructor can be used without
qualification: Person joe=Person("Joe", "Jones");.
The constructor is now easy to use, but it is quite a hassle to define. If you write a lot of
constructors, you will find that you are repeating a lot of code in each of them. Fortunately,
your friendly neighbourhood Asymptote developers have devised a way to automate much
of the process.
If, in the body of a structure, Asymptote encounters the definition of a function of
the form void operator init(args ), it implicitly defines a constructor function of the
arguments args that uses the void operator init function to initialize a new instance
of the structure. That is, it essentially defines the following constructor (assuming the
structure is called Foo):
static Foo Foo(args ) {
Foo instance=new Foo;
instance.operator init(args );
return instance;
}
This constructor is also implicitly copied to the enclosing scope after the end of the
structure definition, so that it can used subsequently without qualifying it by the structure
name. Our Person example can thus be implemented as:
struct Person {
string firstname;
string lastname;
Much like in C++, casting (see Section 5.13 [Casts], page 74) provides for an elegant
implementation of structure inheritance, including virtual functions:
struct parent {
real x;
void operator init(int x) {this.x=x;}
void virtual(int) {write(0);}
void f() {virtual(1);}
}
struct child {
parent parent;
real y=3;
void operator init(int x) {parent.operator init(x);}
void virtual(int x) {write(x);}
parent.virtual=virtual;
void f()=parent.f;
}
parent p=parent(1);
child c=child(2);
write(c); // Outputs 2;
p.f(); // Outputs 0;
c.f(); // Outputs 1;
write(c.parent.x); // Outputs 2;
write(c.y); // Outputs 3;
For further examples of structures, see Legend and picture in the Asymptote base
module plain.
5.9 Operators
5.9.1 Arithmetic & logical operators
Asymptote uses the standard binary arithmetic operators. However, when one integer is
divided by another, both arguments are converted to real values before dividing and a real
quotient is returned (since this is usually what is intended). The function int quotient(int
x, int y) returns the greatest integer less than or equal to x/y. In all other cases both
operands are promoted to the same type, which will also be the type of the result:
+ addition
- subtraction
Chapter 5: Programming 59
* multiplication
/ division
% modulo; the result always has the same sign as the divisor. In particular, this
makes q*quotient(p,q)+p%q == p for all integers p and nonzero integers q.
^ power; if the exponent (second argument) is an int, recursive multiplication is
used; otherwise, logarithms and exponentials are used (** is a synonym for ^).
The usual boolean operators are also defined:
== equals
!= not equals
< less than
<= less than or equals
>= greater than or equals
> greater than
&& and (with conditional evaluation of right-hand argument)
& and
|| or (with conditional evaluation of right-hand argument)
| or
^ xor
! not
Asymptote also supports the C-like conditional syntax:
bool positive=(pi >= 0) ? true : false;
The function T interp(T a, T b, real t) returns (1-t)*a+t*b for nonintegral built-in
arithmetic types T. If a and b are pens, they are first promoted to the same color space.
Asymptote also defines bitwise functions int AND(int,int), int OR(int,int), int
XOR(int,int), and int NOT(int).
However, postfix operators like i++ and i-- are not defined (because of the inherent
ambiguities that would arise with the -- path-joining operator). In the rare instances where
i++ and i-- are really needed, one can substitute the expressions (++i-1) and (--i+1),
respectively.
write(3x);
write(2.5x);
write(3y);
write(-1.602e-19 y);
write(0.5(x,y));
write(2x^2);
Chapter 5: Programming 61
write(3x+2y);
write(3(x+2y));
write(3sin(x));
write(3(sin(x))^2);
write(10cm);
This produces the output
6
5
6
-3.204e-19
(1,1)
8
10
18
2.72789228047704
2.48046543129542
283.464008929116
5.11 Functions
Asymptote functions are treated as variables with a signature (non-function variables have
null signatures). Variables with the same name are allowed, so long as they have distinct
signatures.
Functions arguments are passed by value. To pass an argument by reference, simply
enclose it in a structure (see Section 5.8 [Structures], page 54).
Here are some significant features of Asymptote functions:
1. Variables with signatures (functions) and without signatures (nonfunction variables)
are distinct:
int x, x();
x=5;
x=new int() {return 17;};
x=x(); // calls x() and puts the result, 17, in the scalar x
2. Traditional function definitions are allowed:
int sqr(int x)
{
return x*x;
}
sqr=null; // but the function is still just a variable.
3. Casting can be used to resolve ambiguities:
int a, a(), b, b(); // Valid: creates four variables.
a=b; // Invalid: assignment is ambiguous.
a=(int) b; // Valid: resolves ambiguity.
(int) (a=b); // Valid: resolves ambiguity.
(int) a=b; // Invalid: cast expressions cannot be L-values.
Chapter 5: Programming 62
int c();
c=a; // Valid: only one possible assignment.
4. Anonymous (so-called "high-order") functions are also allowed:
typedef int intop(int);
intop adder(int m)
{
return new int(int n) {return m+n;};
}
intop addby7=adder(7);
write(addby7(1)); // Writes 8.
5. One may redefine a function f, even for calls to f in previously declared functions, by
assigning another (anonymous or named) function to it. However, if f is overloaded
by a new function definition, previous calls will still access the original version of f, as
illustrated in this example:
void f() {
write("hi");
}
void g() {
f();
}
void g(bool b) {
if(b) f(b);
else write(b);
}
f=new void(bool b) {
write(b);
g(false);
};
Chapter 5: Programming 63
sum(1,2,3,4); // returns 10
sum(); // returns 0
subtract(10,1,2); // returns 7
subtract(10); // returns 10
subtract(); // illegal
Putting an argument into a rest array is called packing. One can give an explicit list of
arguments for the rest argument, so subtract could alternatively be implemented as
int subtract(int start ... int[] subs) {
return start - sum(... subs);
}
Chapter 5: Programming 65
g(3,4); // ambiguous; the first candidate is better for the first argument,
// but the second candidate is better for the second argument
i(3,4); // ambiguous; the first candidate is better for the first argument,
// but the second candidate is better for the second one
iteration are printed if verbose=true. If the iteration fails after the maximum
allowed number of loops (iterations), realMax is returned.
real simpson(real f(real), real a, real b, real acc=realEpsilon, real
dxmax=b-a)
returns the integral of f from a to b using adaptive Simpson integration.
5.12 Arrays
Appending [] to a built-in or user-defined type yields an array. The array element i of
an array A can be accessed as A[i]. By default, attempts to access or assign to an array
element using a negative index generates an error. Reading an array element with an index
beyond the length of the array also generates an error; however, assignment to an element
beyond the length of the array causes the array to be resized to accommodate the new
element. One can also index an array A with an integer array B: the array A[B] is formed
by indexing array A with successive elements of array B. A convenient Java-style shorthand
exists for iterating over all elements of an array; see [array iteration], page 23.
The declaration
real[] A;
initializes A to be an empty (zero-length) array. Empty arrays should be distinguished from
null arrays. If we say
real[] A=null;
then A cannot be dereferenced at all (null arrays have no length and cannot be read from
or assigned to).
Arrays can be explicitly initialized like this:
real[] A={0,1,2};
Array assignment in Asymptote does a shallow copy: only the pointer is copied (if one
copy if modified, the other will be too). The copy function listed below provides a deep
copy of an array.
Every array A of type T[] has the virtual members
• int length,
• void cyclic(bool b),
• bool cyclicflag,
• int[] keys,
• T push(T x),
• void append(T[] a),
• T pop(),
• void insert(int i ... T[] x),
• void delete(int i, int j=i),
• void delete(), and
• bool initialized(int n).
The member A.length evaluates to the length of the array. Setting A.cyclic(true)
signifies that array indices should be reduced modulo the current array length. Reading
Chapter 5: Programming 68
from or writing to a nonempty cyclic array never leads to out-of-bounds errors or array
resizing. The member A.cyclicflag returns the current setting of the cyclic flag.
The member A.keys evaluates to an array of integers containing the indices of initialized
entries in the array in ascending order. Hence, for an array of length n with all entries
initialized, A.keys evaluates to the array of integers from 0 to n-1 inclusive. A new keys
array is produced each time A.keys is evaluated.
The functions A.push and A.append append their arguments onto the end of the array,
while A.insert(int i ... T[] x) inserts x into the array at index i. For convenience
A.push returns the pushed item. The function A.pop() pops and returns the last element,
while A.delete(int i, int j=i) deletes elements with indices in the range [i,j], shifting
the position of all higher-indexed elements down. If no arguments are given, A.delete()
provides a convenient way of deleting all elements of A. The routine A.initialized(int
n) can be used to examine whether the element at index n is initialized. Like all Asymptote
functions, cyclic, push, append, pop, insert, delete, and initialized can be "pulled
off" of the array and used on their own. For example,
int[] A={1};
A.push(2); // A now contains {1,2}.
A.append(A); // A now contains {1,2,1,2}.
int f(int)=A.push;
f(3); // A now contains {1,2,1,2,3}.
int g()=A.pop;
write(g()); // Outputs 3.
A.delete(0); // A now contains {2,1,2}.
A.delete(0,1); // A now contains {2}.
A.insert(1,3); // A now contains {2,3}.
A.insert(1 ... A); // A now contains {2,2,3,3}
A.insert(2,4,5); // A now contains {2,2,4,5,3,3}.
The [] suffix can also appear after the variable name; this is sometimes convenient for
declaring a list of variables and arrays of the same type:
real a,A[];
This declares a to be real and implicitly declares A to be of type real[].
In the following list of built-in array functions, T represents a generic type. Note that
the internal functions alias, array, copy, concat, sequence, map, and transpose, which
depend on type T[], are defined only after the first declaration of a variable of type T[].
new T[] returns a new empty array of type T[];
new T[] {list}
returns a new array of type T[] initialized with list (a comma delimited list
of elements).
new T[n] returns a new array of n elements of type T[]. These n array elements are
not initialized unless they are arrays themselves (in which case they are each
initialized to empty arrays).
T[] array(int n, T value, int depth=intMax)
returns an array consisting of n copies of value. By default, if value is itself
an array, a deep copy of that array is made for each entry in the new array.
Chapter 5: Programming 69
If depth is specified, this deep copying only recurses to the number of levels
specified.
int[] sequence(int n)
if n >= 1 returns the array {0,1,...,n-1} (otherwise returns a null array);
int[] sequence(int n, int m)
if m >= n returns an array {n,n+1,...,m} (otherwise returns a null array);
T[] sequence(T f(int), int n)
if n >= 1 returns the sequence {f_i :i=0,1,...n-1} given a function T f(int)
and integer int n (otherwise returns a null array);
T[] map(T f(T), T[] a)
returns the array obtained by applying the function f to each element
of the array a. This is equivalent to sequence(new T(int i) {return
f(a[i]);},a.length).
int[] reverse(int n)
if n >= 1 returns the array {n-1,n-2,...,0} (otherwise returns a null array);
int[] complement(int[] a, int n)
returns the complement of the integer array a in {0,1,2,...,n-1}, so that
b[complement(a,b.length)] yields the complement of b[a].
real[] uniform(real a, real b, int n)
if n >= 1 returns a uniform partition of [a,b] into n subintervals (otherwise
returns a null array);
int find(bool[], int n=1)
returns the index of the nth true value or -1 if not found. If n is negative,
search backwards from the end of the array for the -nth value;
int search(T[] a, T key)
For built-in ordered types T, searches a sorted ordered array a of n elements to
find an interval containing key, returning -1 if key is less than the first element,
n-1 if key is greater than or equal to the last element, and otherwise the index
corresponding to the left-hand (smaller) endpoint.
T[] copy(T[] a)
returns a deep copy of the array a;
T[][] copy(T[][] a)
returns a deep copy of the array a;
T[][][] copy(T[][][] a)
returns a deep copy of the array a;
T[] concat(... T[][] a)
returns a new array formed by concatenating the arrays given as arguments;
bool alias(T[] a, T[] b)
returns true if the arrays a and b are identical;
T[] sort(T[] a)
For built-in ordered types T, returns a copy of a sorted in ascending order;
Chapter 5: Programming 70
T[][] sort(T[][] a)
For built-in ordered types T, returns a copy of a with the rows sorted by the
first column, breaking ties with successively higher columns. For example:
string[][] a={{"bob","9"},{"alice","5"},{"pete","7"},
{"alice","4"}};
// Row sort (by column 0, using column 1 to break ties):
write(sort(a));
produces
alice 4
alice 5
bob 9
pete 7
T[] sort(T[] a, bool compare(T i, T j))
returns a copy of a stably sorted in ascending order such that element i precedes
element j if compare(i,j) is true.
T[][] transpose(T[][] a)
returns the transpose of a.
T[][][] transpose(T[][][] a, int[] perm)
returns the 3D transpose of a obtained by applying the permutation perm of
new int[]{0,1,2} to the indices of each entry.
T sum(T[] a)
For arithmetic types T, returns the sum of a. In the case where T is bool, the
number of true elements in a is returned.
T min(T[] a)
T min(T[][] a)
T min(T[][][] a)
For built-in ordered types T, returns the minimum element of a.
T max(T[] a)
T max(T[][] a)
T max(T[][][] a)
For built-in ordered types T, returns the maximum element of a.
T[] min(T[] a, T[] b)
For built-in ordered types T, and arrays a and b of the same length, returns an
array composed of the minimum of the corresponding elements of a and b.
T[] max(T[] a, T[] b)
For built-in ordered types T, and arrays a and b of the same length, returns an
array composed of the maximum of the corresponding elements of a and b.
pair[] pairs(real[] x, real[] y);
For arrays x and y of the same length, returns the pair array sequence(new
pair(int i) {return (x[i],y[i]);},x.length).
pair[] fft(pair[] a, int sign=1)
returns the Fast Fourier Transform of a (if the optional FFTW package is
installed), using the given sign. Here is a simple example:
Chapter 5: Programming 71
int n=4;
pair[] f=sequence(n);
write(f);
pair[] g=fft(f,-1);
write();
write(g);
f=fft(g,1);
write();
write(f/n);
real dot(real[] a, real[] b)
returns the dot product of the vectors a and b.
real[] tridiagonal(real[] a, real[] b, real[] c, real[] f);
Solve the periodic tridiagonal problem Lx = f and return the solution x, where
f is an n vector and L is the n × n matrix
[ b[0] c[0] a[0] ]
[ a[1] b[1] c[1] ]
[ a[2] b[2] c[2] ]
[ ... ]
[ c[n-1] a[n-1] b[n-1] ]
For Dirichlet boundary conditions (denoted here by u[-1] and u[n]), replace
f[0] by f[0]-a[0]u[-1] and f[n-1]-c[n-1]u[n]; then set a[0]=c[n-1]=0.
real[] solve(real[][] a, real[] b, bool warn=true)
Solve the linear equation ax = b by LU decomposition and return the solution
x, where a is an n × n matrix and b is an array of length n. For example:
import math;
real[][] a={{1,-2,3,0},{4,-5,6,2},{-7,-8,10,5},{1,50,1,-2}};
real[] b={7,19,33,3};
real[] x=solve(a,b);
write(a); write();
write(b); write();
write(x); write();
write(a*x);
If a is a singular matrix and warn is false, return an empty array. If the matrix
a is tridiagonal, the routine tridiagonal provides a more efficient algorithm
(see [tridiagonal], page 71).
real[][] solve(real[][] a, real[][] b, bool warn=true)
Solve the linear equation ax = b and return the solution x, where a is an n × n
matrix and b is an n × m matrix. If a is a singular matrix and warn is false,
return an empty matrix.
real[][] identity(int n);
returns the n × n identity matrix.
real[][] diagonal(... real[] a)
returns the diagonal matrix with diagonal entries given by a.
Chapter 5: Programming 72
real[][] inverse(real[][] a)
returns the inverse of a square matrix a.
real[] quadraticroots(real a, real b, real c);
This numerically robust solver returns the real roots of the quadratic equation
ax2 + bx + c = 0, in ascending order. Multiple roots are listed separately.
pair[] quadraticroots(explicit pair a, explicit pair b, explicit pair c);
This numerically robust solver returns the two complex roots of the quadratic
equation ax2 + bx + c = 0.
real[] cubicroots(real a, real b, real c, real d);
This numerically robust solver returns the real roots of the cubic equation
ax3 + bx2 + cx + d = 0. Multiple roots are listed separately.
Asymptote includes a full set of vectorized array instructions for arithmetic (including
self) and logical operations. These element-by-element instructions are implemented in C++
code for speed. Given
real[] a={1,2};
real[] b={3,2};
then a == b and a >= 2 both evaluate to the vector {false, true}. To test whether all
components of a and b agree, use the boolean function all(a == b). One can also use
conditionals like (a >= 2) ? a : b, which returns the array {3,2}, or write((a >= 2) ? a :
null, which returns the array {2}.
All of the standard built-in libm functions of signature real(real) also take a real array
as an argument, effectively like an implicit call to map.
As with other built-in types, arrays of the basic data types can be read in by assignment.
In this example, the code
file fin=input("test.txt");
real[] A=fin;
reads real values into A until the end-of-file is reached (or an I/O error occurs). If line mode
is set with line(file), then reading will stop once the end of the line is reached instead
(line mode may be cleared with line(file,false)):
file fin=input("test.txt");
real[] A=line(fin);
Since string reads by default read up to the end of line anyway, line mode normally
has no effect on string array reads. However, there is a white-space delimiter mode for
reading strings, set with word(file) and cleared with word(file,false), which causes
string reads to respect white-space delimiters, instead of the default end-of-line delimiter:
file fin=word(line(input("test.txt")));
real[] A=fin;
Another useful mode is comma-separated-value mode, set with csv(file) and cleared
with csv(file,false), which causes reads to respect comma delimiters:
file fin=csv(input("test.txt"));
real[] A=fin;
To restrict the number of values read, use the dimension(file,int) function:
Chapter 5: Programming 73
file fin=input("test.txt");
real[] A=dimension(fin,10);
This reads 10 values into A, unless end-of-file (or end-of-line in line mode) occurs first.
Attempting to read beyond the end of the file will produce a runtime error message.
Specifying a value of 0 for the integer limit is equivalent to the previous example of reading
until end-of-file (or end-of-line in line mode) is encountered.
Two- and three-dimensional arrays of the basic data types can be read in like this:
file fin=input("test.txt");
real[][] A=dimension(fin,2,3);
real[][][] B=dimension(fin,2,3,4);
Again, an integer limit of zero means no restriction.
Sometimes the array dimensions are stored with the data as integer fields at the beginning
of an array. Such arrays can be read in with the functions read1, read2, and read3,
respectively:
file fin=input("test.txt");
real[] A=read1(fin);
real[][] B=read2(fin);
real[][][] C=read3(fin);
One, two, and three-dimensional arrays of the basic data types can be output with the
functions write(file,T[]), write(file,T[][]), write(file,T[][][]), respectively.
Note that dimension, line, csv, word, single, and signed modify and return their
file arguments (to facilitate nested function calls). The virtual members dimension, line,
csv, and word may be used to query the respective parameters for a given file.
5.12.1 Slices
Asymptote allows a section of an array to be addressed as a slice using a Python-like syntax.
If A is an array, the expression A[m:n] returns a new array consisting of the elements of A
with indices from m up to but not including n. For example,
int[] x={0,1,2,3,4,5,6,7,8,9};
int[] y=x[2:6]; // y={2,3,4,5};
int[] z=x[5:10]; // z={5,6,7,8,9};
If the left index is omitted, it is taken be 0. If the right index is omitted it is taken to be
the length of the array. If both are omitted, the slice then goes from the start of the array
to the end, producing a non-cyclic deep copy of the array. For example:
int[] x={0,1,2,3,4,5,6,7,8,9};
int[] y=x[:4]; // y={0,1,2,3}
int[] z=x[5:]; // z={5,6,7,8,9}
int[] w=x[:]; // w={0,1,2,3,4,5,6,7,8,9}, distinct from array x.
If A is a non-cyclic array, it is illegal to use negative values for either of the indices.
If the indices exceed the length of the array, however, they are politely truncated to that
length.
For cyclic arrays, the slice A[m:n] still consists of the cells with indices in the set [m,n),
but now negative values and values beyond the length of the array are allowed. The indices
simply wrap around. For example:
Chapter 5: Programming 74
int[] x={0,1,2,3,4,5,6,7,8,9};
x.cyclic(true);
int[] y=x[8:15]; // y={8,9,0,1,2,3,4}.
int[] z=x[-5:5]; // z={5,6,7,8,9,0,1,2,3,4}
int[] w=x[-3:17]; // w={7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6}
Notice that with cyclic arrays, it is possible to include the same element of the original
array multiple times within a slice. Regardless of the original array, arrays produced by
slices are always non-cyclic.
If the left and right indices of a slice are the same, the result is an empty array. If the
array being sliced is empty, the result is an empty array. Any slice with a left index greater
than its right index will yield an error.
Slices can also be assigned to, changing the value of the original array. If the array being
assigned to the slice has a different length than the slice itself, elements will be inserted or
removed from the array to accommodate it. For instance:
string[] toppings={"mayo", "salt", "ham", "lettuce"};
toppings[0:2]=new string[] {"mustard", "pepper"};
// Now toppings={"mustard", "pepper", "ham", "lettuce"}
toppings[2:3]=new string[] {"turkey", "bacon" };
// Now toppings={"mustard", "pepper", "turkey", "bacon", "lettuce"}
toppings[0:3]=new string[] {"tomato"};
// Now toppings={"tomato", "bacon", "lettuce"}
If an array is assigned to a slice of itself, a copy of the original array is assigned to the
slice. That is, code such as x[m:n]=x is equivalent to x[m:n]=copy(x). One can use the
shorthand x[m:m]=y to insert the contents of the array y into the array x starting at the
location just before x[m].
For a cyclic array, a slice is bridging if it addresses cells up to the end of the array and
then continues on to address cells at the start of the array. For instance, if A is a cyclic array
of length 10, A[8:12], A[-3:1], and A[5:25] are bridging slices whereas A[3:7], A[7:10],
A[-3:0] and A[103:107] are not. Bridging slices can only be assigned to if the number
of elements in the slice is exactly equal to the number of elements we are assigning to it.
Otherwise, there is no clear way to decide which of the new entries should be A[0] and an
error is reported. Non-bridging slices may be assigned an array of any length.
For a cyclic array A an expression of the form A[A.length:A.length] is equivalent to
the expression A[0:0] and so assigning to this slice will insert values at the start of the
array. A.append() can be used to insert values at the end of the array.
It is illegal to assign to a slice of a cyclic array that repeats any of the cells.
5.13 Casts
Asymptote implicitly casts int to real, int to pair, real to pair, pair to path, pair to
guide, path to guide, guide to path, real to pen, pair[] to guide[], pair[] to path[],
path to path[], and guide to path[], along with various three-dimensional casts defined
in three.asy. Implicit casts are automatically attempted on assignment and when trying
to match function calls with possible function signatures. Implicit casting can be inhibited
by declaring individual arguments explicit in the function signature, say to avoid an
ambiguous function call in the following example, which outputs 0:
Chapter 5: Programming 75
write(f(0));
Other conversions, say real to int or real to string, require an explicit cast:
int i=(int) 2.5;
string s=(string) 2.5;
real[] a={2.5,-3.5};
int[] b=(int []) a;
write(stdout,b); // Outputs 2,-3
Casting to user-defined types is also possible using operator cast:
struct rpair {
real radius;
real angle;
}
rpair x;
x.radius=1;
x.angle=pi/6;
5.14 Import
While Asymptote provides many features by default, some applications require specialized
features contained in external Asymptote modules. For instance, the lines
access graph;
graph.axes();
draw x and y axes on a two-dimensional graph. Here, the command looks up the module
under the name graph in a global dictionary of modules and puts it in a new variable named
Chapter 5: Programming 76
graph. The module is a structure, and we can refer to its fields as we usually would with a
structure.
Often, one wants to use module functions without having to specify the module name.
The code
from graph access axes;
adds the axes field of graph into the local name space, so that subsequently, one can just
write axes(). If the given name is overloaded, all types and variables of that name are
added. To add more than one name, just use a comma-separated list:
from graph access axes, xaxis, yaxis;
Wild card notation can be used to add all non-private fields and types of a module to the
local name space:
from graph access *;
Similarly, one can add the non-private fields and types of a structure to the local
environment with the unravel keyword:
struct matrix {
real a,b,c,d;
}
real det(matrix m) {
unravel m;
return a*d-b*c;
}
Alternatively, one can unravel selective fields:
real det(matrix m) {
from m unravel a,b,c as C,d;
return a*d-b*C;
}
The command
import graph;
is a convenient abbreviation for the commands
access graph;
unravel graph;
That is, import graph first loads a module into a structure called graph and then adds
its non-private fields and types to the local environment. This way, if a member variable
(or function) is overwritten with a local variable (or function of the same signature), the
original one can still be accessed by qualifying it with the module name.
Wild card importing will work fine in most cases, but one does not usually know all of the
internal types and variables of a module, which can also change as the module writer adds
or changes features of the module. As such, it is prudent to add import commands at the
start of an Asymptote file, so that imported names won’t shadow locally defined functions.
Still, imported names may shadow other imported names, depending on the order in which
they were imported, and imported functions may cause overloading resolution problems if
they have the same name as local functions defined later.
To rename modules or fields when adding them to the local environment, use as:
Chapter 5: Programming 77
include graph;
include "/usr/local/share/asymptote/graph.asy";
To list all global functions and variables defined in a module named by the contents of
the string s, use the function
void list(string s, bool imports=false);
Imported global functions and variables are also listed if imports is true.
5.15 Static
Static qualifiers allocate the memory address of a variable in a higher enclosing level.
For a function body, the variable is allocated in the block where the function is defined;
so in the code
struct s {
int count() {
static int c=0;
++c;
return c;
}
}
there is one instance of the variable c for each object s (as opposed to each call of count).
Similarly, in
int factorial(int n) {
int helper(int k) {
static int x=1;
x *= k;
return k == 1 ? x : helper(k-1);
}
return helper(n);
}
there is one instance of x for every call to factorial (and not for every call to helper), so
this is a correct, but ugly, implementation of factorial.
Similarly, a static variable declared within a structure is allocated in the block where
the structure is defined. Thus,
struct A {
struct B {
static pair z;
}
}
creates one object z for each object of type A created.
In this example,
int pow(int n, int k) {
struct A {
static int x=1;
void helper() {
Chapter 5: Programming 79
x *= n;
}
}
for(int i=0; i < k; ++i) {
A a;
a.helper();
}
return A.x;
}
there is one instance of x for each call to pow, so this is an ugly implementation of
exponentiation.
Loop constructs allocate a new frame in every iteration. This is so that higher-order
functions can refer to variables of a specific iteration of a loop:
void f();
for(int i=0; i < 10; ++i) {
int x=i;
if(x==5) {
f=new void () { write(x); }
}
}
f();
Here, every iteration of the loop has its own variable x, so f() will write 5. If a variable
in a loop is declared static, it will be allocated where the enclosing function or structure
was defined (just as if it were declared static outside of the loop). For instance, in:
void f() {
static int x;
for(int i=0; i < 10; ++i) {
static int y;
}
}
both x and y will be allocated in the same place, which is also where f is also allocated.
Statements may also be declared static, in which case they are run at the place where
the enclosing function or structure is defined. Declarations or statements not enclosed
in a function or structure definition are already at the top level, so static modifiers are
meaningless. A warning is given in such a case.
Since structures can have static fields, it is not always clear for a qualified name whether
the qualifier is a variable or a type. For instance, in:
struct A {
static int x;
}
pair A;
int y=A.x;
does the A in A.x refer to the structure or to the pair variable. It is the convention in
Asymptote that, if there is a non-function variable with the same name as the qualifier, the
Chapter 5: Programming 80
qualifier refers to that variable, and not to the type. This is regardless of what fields the
variable actually possesses.
Chapter 6: LaTeX usage 81
6 LaTeX usage
Asymptote comes with a convenient LaTeX style file asymptote.sty that makes LaTeX
Asymptote-aware. Entering Asymptote code directly into the LaTeX source file, at the point
where it is needed, keeps figures organized and avoids the need to invent new file names
for each figure. Simply add the line \usepackage{asymptote} at the beginning of your file
and enclose your Asymptote code within a \begin{asy}...\end{asy} environment. As
with the LaTeX comment environment, the \end{asy} command must appear on a line by
itself, with no leading spaces or trailing commands/comments.
The sample LaTeX file below, named latexusage.tex, can be run as follows:
latex latexusage
asy latexusage
latex latexusage
or
pdflatex latexusage
asy latexusage
pdflatex latexusage
To switch between using latex and pdflatex you may first need to remove the files
latexusage-*, latexusage_.pre, and latexusage.aux.
One can specify width, height, viewportwidth, viewportheight, and attach
keyval-style options to the asy environment. The current version (1.07) of asymptote.sty
supports the embedding of 3D PRC files, either inline or, using the attach option with
the attachfile2 (or older attachfile) LaTeX package, as annotated (but printable)
attachments. For many applications, the annotated attachment method tends to be more
convenient. The default value of viewportwidth is \the\linewidth for inline 3D figures
and 0 for attachments.
If the inline option is given to the asymptote.sty package, inline LaTeX code is
generated instead of EPS or PDF files. This makes 2D LaTeX symbols visible to the
\begin{asy}...\end{asy} environment. In this mode, Asymptote correctly aligns 2D
LaTeX symbols defined outside of \begin{asy}...\end{asy}, but treats their size as zero;
an optional second string can be given to Label to provide an estimate of the unknown
label size.
Note that if latex is used with the inline option, the labels might not show up in
DVI viewers that cannot handle raw PostScript code. One can use dvips/dvipdf to
produce PostScript/PDF output (we recommend using the modified version of dvipdf in
the Asymptote patches directory, which accepts the dvips -z hyperdvi option).
An excellent tutorial by Dario Teixeira on integrating Asymptote and LaTeX is available
at http://dario.dse.nl/projects/asylatex/.
Here now is latexusage.tex:
\documentclass[12pt]{article}
% Use this form with latex or pdflatex to include inline LaTeX code:
%\usepackage[inline]{asymptote}
% Enable this line for PDF attachments with asy environment option attach=true:
%\usepackage[dvips]{attachfile2}
\begin{document}
\begin{asydef}
// Global Asymptote definitions can be put here.
usepackage("bm");
texpreamble("\def\V#1{\bm{#1}}");
// One can globally override the default toolbar settings here:
// settings.toolbar=true;
\end{asydef}
\def\A{A}
\def\B{\V{B}}
%\begin{figure}
\begin{center}
\begin{asy}
size(4cm,0);
pen colour1=red;
pen colour2=green;
pair z0=(0,0);
pair z1=(-1,0);
pair z2=(1,0);
real r=1.5;
path c1=circle(z1,r);
path c2=circle(z2,r);
fill(c1,colour1);
fill(c2,colour2);
add(intersection);
draw(c1);
Chapter 6: LaTeX usage 83
draw(c2);
pair z=(0,-2);
real m=3;
margin BigMargin=Margin(0,m*dot(unit(z1-z),unit(z0-z)));
draw(Label("$A\cap B$",0),conj(z)--z0,Arrow,BigMargin);
draw(Label("$A\cup B$",0),z--z0,Arrow,BigMargin);
draw(z--z1,Arrow,Margin(0,m));
draw(z--z2,Arrow,Margin(0,m));
shipout(bbox(0.25cm));
\end{asy}
%\caption{Venn diagram}\label{venn}
\end{center}
%\end{figure}
Each graph is drawn in its own environment. One can specify the width
and height to \LaTeX\ explicitly. This 3D example can be viewed
interactively either with Adobe Reader or Asymptote’s fast OpenGL-based
renderer. It is often desirable to embed such files as annotated attachments;
this requires the optional \verb+\usepackage{attachfile2}+ package and
the \verb+{attach=true}+ option:
\begin{center}
\begin{asy}[height=4cm,attach=false]
import three;
currentprojection=orthographic(5,4,2);
draw(unitcube,blue);
label("$V-E+F=2$",(0,1,0.5),3Y,blue+fontsize(17));
\end{asy}
\end{center}
One can also scale the figure to the full line width:
\begin{center}
\begin{asy}[width=\the\linewidth]
pair z0=(0,0);
pair z1=(2,0);
pair z2=(5,0);
pair zf=z1+0.75*(z2-z1);
draw(z1--z2);
dot(z1,red+0.15cm);
Chapter 6: LaTeX usage 84
dot(z2,darkgreen+0.3cm);
label("$m$",z1,1.2N,red);
label("$M$",z2,1.5N,darkgreen);
label("$\hat{\ }$",zf,0.2*S,fontsize(24)+blue);
pair s=-0.2*I;
draw("$x$",z0+s--z1+s,N,red,Arrows,Bars,PenMargins);
s=-0.5*I;
draw("$\bar{x}$",z0+s--zf+s,blue,Arrows,Bars,PenMargins);
s=-0.95*I;
draw("$X$",z0+s--z2+s,darkgreen,Arrows,Bars,PenMargins);
\end{asy}
\end{center}
\end{document}
Chapter 6: LaTeX usage 85
A∩B
A B
A∪B
Each graph is drawn in its own environment. One can specify the width
and height to LATEX explicitly. This 3D example can be viewed interactively
either with Adobe Reader or Asymptote’s fast OpenGL-based renderer. It
is often desirable to embed such files as annotated attachments; this requires
the optional \usepackage{attachfile2} package and the {attach=true}
option:
One can also scale the figure to the full line width:
m M
x
ˆ
x̄
1
Chapter 7: Base modules 86
7 Base modules
Asymptote currently ships with the following base modules:
7.1 plain
This is the default Asymptote base file, which defines key parts of the drawing language
(such as the picture structure).
By default, an implicit private import plain; occurs before translating a file and
before the first command given in interactive mode. This also applies when translating
files for module definitions (except when translating plain, of course). This means that the
types and functions defined in plain are accessible in almost all Asymptote code. Use the
-noautoplain command-line option to disable this feature.
7.2 simplex
This package solves the two-variable linear programming problem using the simplex method.
It is used by the module plain for automatic sizing of pictures.
7.3 math
This package extends Asymptote’s mathematical capabilities with intersection algorithms
and matrix arithmetic:
void drawline(picture pic=currentpicture, pair P, pair Q, pen p=currentpen);
draw the visible portion of the (infinite) line going through P and Q, without
altering the size of picture pic, using pen p.
real intersect(triple P, triple Q, triple n, triple Z);
returns the intersection time of the extension of the line segment PQ with the
plane perpendicular to n and passing through Z.
triple intersectionpoint(triple n0, triple P0, triple n1, triple P1);
Return any point on the intersection of the two planes with normals n0 and
n1 passing through points P0 and P1, respectively. If the planes are parallel,
return (infinity,infinity,infinity).
pair[] quarticroots(real a, real b, real c, real d, real e);
returns the four complex roots of the quartic equation ax4 +bx3 +cx2 +dx+e = 0.
7.4 interpolate
This module implements Lagrange, Hermite, and standard cubic spline interpolation in
Asymptote, as illustrated in the example interpolate1.asy.
7.5 geometry
This module, written by Philippe Ivaldi, provides an extensive set of geometry
routines, including perpendicular symbols and a triangle structure.
Link to the documentation for the geometry module are posted here:
http://asymptote.sourceforge.net/links.html, including an extensive set of
Chapter 7: Base modules 87
7.6 trembling
This module, written by Philippe Ivaldi and illustrated in the example floatingdisk.asy,
allows one to draw wavy lines, as if drawn by hand. Further examples are posted at
http://piprim.tuxfamily.org/asymptote/trembling/index.html
7.7 stats
This package implements a Gaussian random number generator and a collection of statistics
routines, including histogram and leastsquares.
7.8 patterns
This package implements Postscript tiling patterns and includes several convenient pattern
generation routines.
7.9 markers
This package implements specialized routines for marking paths and angles. The principal
mark routine provided by this package is
markroutine markinterval(int n=1, frame f, bool rotated=false);
which centers n copies of frame f within uniformly space intervals in arclength along the
path, optionally rotated by the angle of the local tangent.
The marker (see [marker], page 103) routine can be used to construct new markers from
these predefined frames:
frame stickframe(int n=1, real size=0, pair space=0, real angle=0,
pair offset=0, pen p=currentpen);
frame circlebarframe(int n=1, real barsize=0,
real radius=0,real angle=0,
pair offset=0, pen p=currentpen,
filltype filltype=NoFill, bool above=false);
frame crossframe(int n=3, real size=0, pair space=0,
real angle=0, pair offset=0, pen p=currentpen);
frame tildeframe(int n=1, real size=0, pair space=0,
real angle=0, pair offset=0, pen p=currentpen);
For convenience, this module also constructs the markers StickIntervalMarker,
CrossIntervalMarker, CircleBarIntervalMarker, and TildeIntervalMarker from the
above frames. The example markers1.asy illustrates the use of these markers:
Chapter 7: Base modules 88
1 2
3 4
5 6
7 8
9 10
11 12
13 14
a
a
15 16
a
a a
17
γ
C
−θ
θ F
D A B
7.10 tree
This package implements an example of a dynamic binary search tree.
7.11 binarytree
This module can be used to draw an arbitrary binary tree and includes an input routine for
the special case of a binary search tree, as illustrated in the example binarytreetest.asy:
import binarytree;
picture pic,pic2;
binarytree bt=binarytree(1,2,4,nil,5,nil,nil,0,nil,nil,3,6,nil,nil,7);
draw(pic,bt);
binarytree st=searchtree(10,5,2,1,3,4,7,6,8,9,15,13,12,11,14,17,16,18,19);
draw(pic2,st,blue);
add(pic.fit(),(0,0),10N);
add(pic2.fit(),(0,0),10S);
Chapter 7: Base modules 90
2 3
4 0 6 7
10
5 15
2 7 13 17
1 3 6 8 12 14 16 18
4 9 11 19
7.12 drawtree
This is a simple tree drawing module used by the example treetest.asy.
7.13 syzygy
This module automates the drawing of braids, relations, and syzygies, along with the
corresponding equations, as illustrated in the example knots.asy.
7.14 feynman
This package, contributed by Martin Wiebusch, is useful for drawing Feynman diagrams,
as illustrated by the examples eetomumu.asy and fermi.asy.
7.15 roundedpath
This package, contributed by Stefan Knorr, is useful for rounding the sharp corners of paths,
as illustrated in the example file roundpath.asy.
7.16 animation
This module allows one to generate animations, as illustrated by the files wheel.asy,
wavelet.asy, and cube.asy in the animations subdirectory of the examples directory.
Chapter 7: Base modules 91
These animations use the ImageMagick convert program to merge multiple images into a
GIF or MPEG movie.
The related animate module, derived from the animation module, generates higher-
quality portable clickable PDF movies, with optional controls. This requires installing the
package
http://www.ctan.org/tex-archive/macros/latex/contrib/animate/animate.sty
(version 2007/11/30 or later) in a new directory animate in the local LaTeX directory (for
example, in /usr/local/share/texmf/tex/latex/animate). On UNIX systems, one must
then execute the command texhash.
The example pdfmovie.asy in the animations directory, along with the slide
presentations slidemovies.asy and intro.asy, illustrate the use of embedded PDF
movies. The examples inlinemovie.tex and inlinemovie3.tex show how to generate
and embed PDF movies directly within a LaTeX file (see Chapter 6 [LaTeX usage],
page 81). The member function
string pdf(fit fit=NoBox, real delay=animationdelay, string options="",
bool keep=settings.keep, bool multipage=true);
of the animate structure accepts any of the animate.sty options, as described here:
http://www.ctan.org/tex-archive/macros/latex/contrib/animate/doc/animate.pdf
7.17 embed
This module provides an interface to the LaTeX package (included with MikTeX)
http://www.ctan.org/tex-archive/macros/latex/contrib/movie15
for embedding movies, sounds, and 3D objects into a PDF document. However, XeLaTeX
users need to rename the modified version movie15_dvipdfmx.sty from
http://asymptote.svn.sourceforge.net/viewvc/asymptote/trunk/asymptote/patches/
to movie15.sty and place it in their LaTeX path.
The latest version of the movie15 package requires both pdflatex version 1.20 or later
and the file
http://www.ctan.org/tex-archive/macros/latex/contrib/oberdiek/ifdraft.dtx
which can be installed by placing it in a directory ifdraft in the local LaTeX directory
(e.g. /usr/local/share/texmf/tex/latex/ifdraft) and executing in that directory the
commands:
tex ifdraft.dtx
texhash
An example of embedding U3D code is provided in the file embeddedu3d.asy. As of
version 7.0.8, Adobe Reader supports the U3D format under Linux.
Unfortunately, Adobe has not yet made available an embedded movie plugin for the
Linux version of Adobe Reader. A portable method for embedding movie files, which should
work on any platform and does not require the movie15 or ifdraft packages, is provided
by using the external module instead of embed. An example of these interfaces is provided
in the file embeddedmovie.asy and externalmovie.asy in the animations subdirectory
of the examples directory. For a higher quality movie generated directly by Asymptote,
use the animate module along with the animate.sty package to embed a portable PDF
animation (see [animate], page 91).
Chapter 7: Base modules 92
7.18 slide
This package provides a simple yet high-quality facility for making presentation slides,
including portable embedded PDF animations (see the file slidemovies.asy). A simple
example is provided in the file slidedemo.asy.
7.19 MetaPost
This package provides some useful routines to help MetaPost users migrate old MetaPost
code to Asymptote. Further contributions here are welcome.
Unlike MetaPost, Asymptote does not implicitly solve linear equations and therefore
does not have the notion of a whatever unknown. The routine extension (see [extension],
page 33) provides a useful replacement for a common use of whatever: finding the
intersection point of the lines through P, Q and p, q. For less common occurrences of
whatever, one can use the built-in explicit linear equation solver solve instead.
7.20 unicode
Import this package at the beginning of the file to instruct LaTeX to accept unicode (UTF-
8) standardized international characters. To use Cyrillic fonts, you will need to change the
font encoding:
import unicode;
texpreamble("\usepackage{mathtext}\usepackage[russian]{babel}");
defaultpen(font("T2A","cmr","m","n"));
Support for Chinese, Japanese, and Korean fonts is provided by the CJK package:
http://www.ctan.org/tex-archive/languages/chinese/CJK/
The following commands enable the CJK song family (within a label, you can also
temporarily switch to another family, say kai, by prepending "\CJKfamily{kai}" to the
label string):
texpreamble("\usepackage{CJK}
\AtBeginDocument{\begin{CJK*}{GBK}{song}}
\AtEndDocument{\clearpage\end{CJK*}}");
7.21 latin1
If you don’t have LaTeX support for unicode installed, you can enable support for Western
European languages (ISO 8859-1) by importing the module latin1. This module can be
used as a template for providing support for other ISO 8859 alphabets.
7.22 babel
This module implements the LaTeX babel package in Asymptote. For example:
import babel;
babel("german");
Chapter 7: Base modules 93
7.23 labelpath
This module uses the PSTricks pstextpath macro to fit labels along a path (properly
kerned, as illustrated in the example file curvedlabel.asy), using the command
void labelpath(picture pic=currentpicture, Label L, path g,
string justify=Centered, pen p=currentpen);
Here justify is one of LeftJustified, Centered, or RightJustified. The x component
of a shift transform applied to the Label is interpreted as a shift along the curve, whereas
the y component is interpreted as a shift away from the curve. All other Label transforms
are ignored. This package requires the latex tex engine and inherits the limitations of the
PSTricks \pstextpath macro.
7.24 labelpath3
This module, contributed by Jens Schwaiger, implements a 3D version of labelpath that
does not require the PSTricks package. An example is provided in curvedlabel3.asy.
7.25 annotate
This module supports PDF annotations for viewing with Adobe Reader, via the function
void annotate(picture pic=currentpicture, string title, string text,
pair position);
Annotations are illustrated in the example file annotation.asy. Currently, annotations are
only implemented for the latex (default) and tex TEX engines.
7.26 CAD
This package, contributed by Mark Henning, provides basic pen definitions and
measurement functions for simple 2D CAD drawings according to DIN 15. It is
documented separately, in the file CAD.pdf.
7.27 graph
This package implements two-dimensional linear and logarithmic graphs, including
automatic scale and tick selection (with the ability to override manually). A graph is a
guide (that can be drawn with the draw command, with an optional legend) constructed
with one of the following routines:
•
guide graph(picture pic=currentpicture, real f(real), real a, real b,
int n=ngraph, real T(real)=identity,
interpolate join=operator --);
guide[] graph(picture pic=currentpicture, real f(real), real a, real b,
int n=ngraph, real T(real)=identity, bool3 cond(real),
interpolate join=operator --);
Returns a graph using the scaling information for picture pic (see [automatic scaling],
page 109) of the function f on the interval [T(a),T(b)], sampling at n points evenly
spaced in [a,b], optionally restricted by the bool3 function cond on [a,b]. If cond is:
Chapter 7: Base modules 94
import graph;
The default tick option is NoTicks. The options LeftTicks, RightTicks, or Ticks
can be used to draw ticks on the left, right, or both sides of the path, relative to the
direction in which the path is drawn. These tick routines accept a number of optional
arguments:
ticks LeftTicks(Label format="", ticklabel ticklabel=null,
bool beginlabel=true, bool endlabel=true,
int N=0, int n=0, real Step=0, real step=0,
bool begin=true, bool end=true, tickmodifier modify=None,
real Size=0, real size=0, bool extend=false,
pen pTick=nullpen, pen ptick=nullpen);
If any of these parameters are omitted, reasonable defaults will be chosen:
Label format
override the default tick label format (defaultformat, initially
"$%.4g$"), rotation, pen, and alignment (for example, LeftSide, Center,
or RightSide) relative to the axis. To enable LaTeX math mode fonts,
the format string should begin and end with $ see [format], page 27. If
the format string is trailingzero, trailing zeros will be added to the tick
labels; if the format string is "%", the tick label will be suppressed;
ticklabel
is a function string(real x) returning the label (by default,
format(format.s,x)) for each major tick value x;
bool beginlabel
include the first label;
bool endlabel
include the last label;
int N when automatic scaling is enabled (the default; see [automatic scaling],
page 109), divide a linear axis evenly into this many intervals, separated
by major ticks; for a logarithmic axis, this is the number of decades between
labelled ticks;
Chapter 7: Base modules 97
int n divide each interval into this many subintervals, separated by minor ticks;
real Step the tick value spacing between major ticks (if N=0);
real step the tick value spacing between minor ticks (if n=0);
bool begin
include the first major tick;
bool end include the last major tick;
tickmodifier modify;
an optional function that takes and returns a tickvalue structure having
real[] members major and minor consisting of the tick values (to allow
modification of the automatically generated tick values);
real Size the size of the major ticks (in PostScript coordinates);
real size the size of the minor ticks (in PostScript coordinates);
bool extend;
extend the ticks between two axes (useful for drawing a grid on the graph);
pen pTick an optional pen used to draw the major ticks;
pen ptick an optional pen used to draw the minor ticks.
For convenience, the predefined tickmodifier OmitTick(... real[] x) tickmodifier
can be used to remove specific auto-generated ticks and their labels. The
OmitFormat(string s=defaultformat ... real[] x) ticklabel can be used to
remove specific tick labels but not the corresponding ticks. The tickmodifier NoZero
is an abbreviation for OmitTick(0) and the ticklabel NoZeroFormat is an abbrevation
for OmitFormat(0).
It is also possible to specify custom tick locations with LeftTicks, RightTicks, and
Ticks by passing explicit real arrays Ticks and (optionally) ticks containing the
locations of the major and minor ticks, respectively:
ticks LeftTicks(Label format="", ticklabel ticklabel=null,
bool beginlabel=true, bool endlabel=true,
real[] Ticks, real[] ticks=new real[],
real Size=0, real size=0, bool extend=false,
pen pTick=nullpen, pen ptick=nullpen)
•
void yaxis(picture pic=currentpicture, Label L="", axis axis=XZero,
real ymin=-infinity, real ymax=infinity, pen p=currentpen,
ticks ticks=NoTicks, arrowbar arrow=None, bool above=false);
Draw a y axis on picture pic from y=ymin to y=ymax using pen p, optionally labelling
it with Label L. The relative location of the label (a real number from [0,1]) defaults to 1
(see [Label], page 19). An infinite value of ymin or ymax specifies that the corresponding
axis limit will be automatically determined from the picture limits. The optional arrow
argument takes the same values as in the draw command (see [arrows], page 15). The
axis is drawn before any existing objects in the current picture unless above=true.
The tick type is specified by ticks and the axis placement is determined by one of the
following axis types:
Chapter 7: Base modules 98
XZero(bool extend=true)
Request a y axis at x=0 (or x=1 on a logarithmic axis) extending to the
full dimensions of the picture, unless extend=false.
XEquals(real X, bool extend=true)
Request a y axis at x=X extending to the full dimensions of the picture,
unless extend=false.
Left(bool extend=false)
Request a left axis.
Right(bool extend=false)
Request a right axis.
LeftRight(bool extend=false)
Request a left and right axis.
• For convenience, the functions
void xequals(picture pic=currentpicture, Label L="", real x,
bool extend=false, real ymin=-infinity, real ymax=infinity,
pen p=currentpen, ticks ticks=NoTicks, bool above=true,
arrowbar arrow=None);
and
void yequals(picture pic=currentpicture, Label L="", real y,
bool extend=false, real xmin=-infinity, real xmax=infinity,
pen p=currentpen, ticks ticks=NoTicks, bool above=true,
arrowbar arrow=None);
can be respectively used to call yaxis and xaxis with the appropriate axis types
XEquals(x,extend) and YEquals(y,extend). This is the recommended way of
drawing vertical or horizontal lines and axes at arbitrary locations.
•
void axes(picture pic=currentpicture, Label xlabel="", Label ylabel="",
pair min=(-infinity,-infinity), pair max=(infinity,infinity),
pen p=currentpen, arrowbar arrow=None, bool above=false);
This convenience routine draws both x and y axes on picture pic from min to max,
with optional labels xlabel and ylabel and any arrows specified by arrow. The axes
are drawn on top of existing objects in the current picture only if above=true.
•
void axis(picture pic=currentpicture, Label L="", path g,
pen p=currentpen, ticks ticks, ticklocate locate,
arrowbar arrow=None, int[] divisor=new int[],
bool above=false, bool opposite=false);
This routine can be used to draw on picture pic a general axis based on an arbitrary
path g, using pen p. One can optionally label the axis with Label L and add an arrow
arrow. The tick type is given by ticks. The optional integer array divisor specifies
what tick divisors to try in the attempt to produce uncrowded tick labels. A true value
for the flag opposite identifies an unlabelled secondary axis (typically drawn opposite
Chapter 7: Base modules 99
a primary axis). The axis is drawn before any existing objects in the current picture
unless above=true. The tick locator ticklocate is constructed by the routine
ticklocate ticklocate(real a, real b, autoscaleT S=defaultS,
real tickmin=-infinity, real tickmax=infinity,
real time(real)=null, pair dir(real)=zero);
where a and b specify the respective tick values at point(g,0) and
point(g,length(g)), S specifies the autoscaling transformation, the func-
tion real time(real v) returns the time corresponding to the value v, and pair
dir(real t) returns the absolute tick direction as a function of t (zero means draw
the tick perpendicular to the axis).
• These routines are useful for manually putting ticks and labels on axes (if the variable
Label is given as the Label argument, the format argument will be used to format a
string based on the tick location):
void xtick(picture pic=currentpicture, Label L="", explicit pair z,
pair dir=N, string format="",
real size=Ticksize, pen p=currentpen);
void xtick(picture pic=currentpicture, Label L="", real x,
pair dir=N, string format="",
real size=Ticksize, pen p=currentpen);
void ytick(picture pic=currentpicture, Label L="", explicit pair z,
pair dir=E, string format="",
real size=Ticksize, pen p=currentpen);
void ytick(picture pic=currentpicture, Label L="", real y,
pair dir=E, string format="",
real size=Ticksize, pen p=currentpen);
void tick(picture pic=currentpicture, pair z,
pair dir, real size=Ticksize, pen p=currentpen);
void labelx(picture pic=currentpicture, Label L="", explicit pair z,
align align=S, string format="", pen p=nullpen);
void labelx(picture pic=currentpicture, Label L="", real x,
align align=S, string format="", pen p=nullpen);
void labelx(picture pic=currentpicture, Label L,
string format="", explicit pen p=currentpen);
void labely(picture pic=currentpicture, Label L="", explicit pair z,
align align=W, string format="", pen p=nullpen);
void labely(picture pic=currentpicture, Label L="", real y,
align align=W, string format="", pen p=nullpen);
void labely(picture pic=currentpicture, Label L,
string format="", explicit pen p=nullpen);
Here are some simple examples of two-dimensional graphs:
1. This example draws a textbook-style graph of y = exp(x), with the y axis starting at
y = 0:
import graph;
size(150,0);
Chapter 7: Base modules 100
xaxis("$x$");
yaxis("$y$",0);
draw(graph(f,-4,2,operator ..),red);
labely(1,E);
label("$e^x$",F(1),SE);
ex
x
2. The next example draws a scientific-style graph with a legend. The position of the
legend can be adjusted either explicitly or by using the graphical user interface xasy (see
Chapter 10 [GUI], page 159). If an UnFill(real xmargin=0, real ymargin=xmargin)
or Fill(pen) option is specified to add, the legend will obscure any underlying objects.
Here we illustrate how to clip the portion of the picture covered by a label:
import graph;
size(400,200,IgnoreAspect);
draw(graph(Sin,0,1),red,"$\sin(2\pi x)$");
draw(graph(Cos,0,1),blue,"$\cos(2\pi x)$");
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks(trailingzero));
label("LABEL",point(0),UnFill(1mm));
Chapter 7: Base modules 101
add(legend(),point(E),20E,UnFill);
1.0
0.5
sin(2πx)
y 0.0 LABEL
cos(2πx)
−0.5
−1.0
0 0.2 0.4 0.6 0.8 1
x
To specify a fixed size for the graph proper, use attach:
import graph;
size(250,200,IgnoreAspect);
draw(graph(Sin,0,1),red,"$\sin(2\pi x)$");
draw(graph(Cos,0,1),blue,"$\cos(2\pi x)$");
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks(trailingzero));
label("LABEL",point(0),UnFill(1mm));
attach(legend(),truepoint(E),20E,UnFill);
A legend can have multiple entries per line:
import graph;
size(8cm,6cm,IgnoreAspect);
draw(graph(F(i*pi),0,1),Pen(i),
"$\sin("+(i == 1 ? "" : (string) i)+"\pi x)$");
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks(trailingzero));
attach(legend(2),(point(S).x,truepoint(S).y),10S,UnFill);
1.0
0.5
y 0.0
−0.5
−1.0
0 0.2 0.4 0.6 0.8 1
x
sin(πx) sin(2πx)
sin(3πx) sin(4πx)
3. This example draws a graph of one array versus another (both of the same size) using
custom tick locations and a smaller font size for the tick labels on the y axis.
import graph;
size(200,150,IgnoreAspect);
real[] x={0,1,2,3};
real[] y=x^2;
draw(graph(x,y),red);
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,
RightTicks(Label(fontsize(8)),new real[]{0,4,9}));
Chapter 7: Base modules 103
9
y
4
0
0 1 2 3
x
4. This example shows how to graph columns of data read from a file.
import graph;
size(200,150,IgnoreAspect);
file in=line(input("filegraph.dat"));
real[][] a=dimension(in,0,0);
a=transpose(a);
real[] x=a[0];
real[] y=a[1];
draw(graph(x,y),red);
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks);
y 1
0
50 70 90 110
x
5. The next example draws two graphs of an array of coordinate pairs, using frame
alignment and data markers. In the left-hand graph, the markers, constructed with
marker marker(path g, markroutine markroutine=marknodes,
pen p=currentpen, filltype filltype=NoFill,
bool above=true);
using the path unitcircle (see [filltype], page 47), are drawn below each node. Any
frame can be converted to a marker, using
Chapter 7: Base modules 104
marker[] MarkFill={
marker(scale(circlescale)*unitcircle,Fill),marker(polygon(3),Fill),
marker(polygon(4),Fill),marker(polygon(5),Fill),
marker(invert*polygon(3),Fill)
};
The example also illustrates the errorbar routines:
void errorbars(picture pic=currentpicture, pair[] z, pair[] dp,
pair[] dm={}, bool[] cond={}, pen p=currentpen,
real size=0);
picture pic;
real xsize=200, ysize=140;
size(pic,xsize,ysize,IgnoreAspect);
pair[] f={(5,5),(50,20),(90,90)};
pair[] df={(0,0),(5,7),(0,5)};
Chapter 7: Base modules 105
errorbars(pic,f,df,red);
draw(pic,graph(pic,f),"legend",
marker(scale(0.8mm)*unitcircle,red,FillDraw(blue),above=false));
scale(pic,true);
xaxis(pic,"$x$",BottomTop,LeftTicks);
yaxis(pic,"$y$",LeftRight,RightTicks);
add(pic,legend(pic),point(pic,NW),20SE,UnFill);
picture pic2;
size(pic2,xsize,ysize,IgnoreAspect);
frame mark;
filldraw(mark,scale(0.8mm)*polygon(6),green,green);
draw(mark,scale(0.8mm)*cross(6),blue);
draw(pic2,graph(pic2,f),marker(mark,markuniform(5)));
scale(pic2,true);
xaxis(pic2,"$x$",BottomTop,LeftTicks);
yaxis(pic2,"$y$",LeftRight,RightTicks);
yequals(pic2,55.0,red+Dotted);
xequals(pic2,70.0,red+Dotted);
100 100
80 80
legend
60 60
y y
40 40
20 20
0 0
0 20 40 60 80 100 0 20 40 60 80 100
x x
import graph;
size(200,100,IgnoreAspect);
markroutine marks() {
return new void(picture pic=currentpicture, frame f, path g) {
path p=scale(1mm)*unitcircle;
for(int i=0; i <= length(g); ++i) {
pair z=point(g,i);
frame f;
if(i % 4 == 0) {
fill(f,p);
add(pic,f,z);
} else {
if(z.y > 50) {
pic.add(new void(frame F, transform t) {
path q=shift(t*z)*p;
unfill(F,q);
draw(F,q);
});
} else {
draw(f,p);
add(pic,f,z);
}
}
}
};
}
pair[] f={(5,5),(40,20),(55,51),(90,30)};
draw(graph(f),marker(marks()));
scale(true);
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks);
60
40
y
20
0
0 20 40 60 80 100
x
Chapter 7: Base modules 107
size(400,150,IgnoreAspect);
real[] x=sequence(12);
real[] y=sin(2pi*x/12);
scale(false);
string[] month={"Jan","Feb","Mar","Apr","May","Jun",
"Jul","Aug","Sep","Oct","Nov","Dec"};
draw(graph(x,y),red,MarkFill[0]);
xaxis(BottomTop,LeftTicks(new string(real x) {
return month[round(x % 12)];}));
yaxis("$y$",LeftRight,RightTicks(4));
0.5
y 0
−0.5
−1
Jan Mar May Jul Sep Nov
8. The next example draws a graph of a parametrized curve. The calls to
xlimits(picture pic=currentpicture, real min=-infinity,
real max=infinity, bool crop=NoCrop);
and the analogous function ylimits can be uncommented to set the respective axes
limits for picture pic to the specified min and max values. Alternatively, the function
void limits(picture pic=currentpicture, pair min, pair max, bool crop=NoCrop);
can be used to limit the axes to the box having opposite vertices at the given pairs).
Existing objects in picture pic will be cropped to lie within the given limits if
crop=Crop. The function crop(picture pic) can be used to crop a graph to the
current graph limits.
import graph;
size(0,200);
draw(graph(x,y,0,1));
//xlimits(0,1,Crop);
//ylimits(-1,0,Crop);
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks(trailingzero));
1.0
0.5
y 0.0
−0.5
−1.0
−1 0 1
x
The next example illustrates how one can extract a common axis scaling factor.
import graph;
axiscoverage=0.9;
size(200,IgnoreAspect);
real[] x={-1e-11,1e-11};
real[] y={0,1e6};
real xscale=round(log10(max(x)));
real yscale=round(log10(max(y)))-1;
draw(graph(x*10^(-xscale),y*10^(-yscale)),red);
xaxis("$x/10^{"+(string) xscale+"}$",BottomTop,LeftTicks);
yaxis("$y/10^{"+(string) yscale+"}$",LeftRight,RightTicks(trailingzero));
Chapter 7: Base modules 109
10
9
8
7
6
y/105
5
4
3
2
1
0
−1 −0.5 0 0.5 1
x/10−11
Axis scaling can be requested and/or automatic selection of the axis limits can be
inhibited with one of these scale routines:
void scale(picture pic=currentpicture, scaleT x, scaleT y);
size(200,200,IgnoreAspect);
scale(Log,Log);
Chapter 7: Base modules 110
draw(graph(f,0.1,10));
//xlimits(1,10,Crop);
//ylimits(0.1,1,Crop);
dot(Label("(3,5)",align=S),Scale((3,5)));
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$y$",LeftRight,RightTicks);
101
(3,5)
y 100
10−1 −1
10 100 101
x
import graph;
size(200,200,IgnoreAspect);
scale(Log,Log);
draw(graph(f,0.1,10),red);
pen thin=linewidth(0.5*linewidth());
xaxis("$x$",BottomTop,LeftTicks(begin=false,end=false,extend=true,
ptick=thin));
yaxis("$y$",LeftRight,RightTicks(begin=false,end=false,extend=true,
ptick=thin));
Chapter 7: Base modules 111
101
y 100
10−1 −1
10 100 101
x
One can also specify custom tick locations and formats for logarithmic axes:
import graph;
size(300,175,IgnoreAspect);
scale(Log,Log);
draw(graph(identity,5,20));
xlimits(5,20);
ylimits(1,100);
xaxis("$M/M_\odot$",BottomTop,LeftTicks(DefaultFormat,
new real[] {6,10,12,14,16,18}));
yaxis("$\nu_{\rm upp}$ [Hz]",LeftRight,RightTicks(DefaultFormat));
100
νupp [Hz]
10
1
6 10 12 14 16 18
M/M⊙
It is easy to draw logarithmic graphs with respect to other bases:
import graph;
size(200,IgnoreAspect);
scaleT yscale=scaleT(log2,pow2,logarithmic=true);
scale(Linear,yscale);
draw(graph(f,-4,4));
yaxis("$y$",ymin=1,ymax=f(5),RightTicks(Label(Fill(white))),EndArrow);
xaxis("$x$",xmin=-5,xmax=5,LeftTicks,EndArrow);
y
24
23
22
21
20
−5 0 5
x
Here is an example of "broken" linear x and logarithmic y axes that omit the segments
[3,8] and [100,1000], respectively. In the case of a logarithmic axis, the break endpoints
are automatically rounded to the nearest integral power of the base.
import graph;
size(200,150,IgnoreAspect);
scale(Broken(a,b),BrokenLog(c,d));
real[] x={1,2,4,6,10};
real[] y=x^4;
Chapter 7: Base modules 113
draw(graph(x,y),red,MarkFill[0]);
xaxis("$x$",BottomTop,LeftTicks(Break(a,b)));
yaxis("$y$",LeftRight,RightTicks(Break(c,d)));
label(rotate(90)*Break,(a,point(S).y));
label(rotate(90)*Break,(a,point(N).y));
label(Break,(point(W).x,ScaleY(c)));
label(Break,(point(E).x,ScaleY(c)));
104
≈
≈ ≈
y
101
100
≈
2 10
x
9. Asymptote can draw secondary axes with the routines
picture secondaryX(picture primary=currentpicture, void f(picture));
picture secondaryY(picture primary=currentpicture, void f(picture));
In this example, secondaryY is used to draw a secondary linear y axis against a primary
logarithmic y axis:
import graph;
texpreamble("\def\Arg{\mathop {\rm Arg}\nolimits}");
size(10cm,5cm,IgnoreAspect);
scale(Log,Log);
draw(graph(ampl,0.01,10));
ylimits(0.001,100);
xaxis("$\omega\tau_0$",BottomTop,LeftTicks);
yaxis("$|G(\omega\tau_0)|$",Left,RightTicks);
ylimits(pic,-1.0,1.5);
yaxis(pic,"$\Arg G/\pi$",Right,red,
LeftTicks("$% #.1f$",
begin=false,end=false));
yequals(pic,1,Dotted);
});
label(q,"(1,0)",Scale(q,(1,0)),red);
add(q);
102 1.5
101 1.0
Arg G/π
|G(ωτ0 )|
100 0.5
10−1 (1,0) 0.0
10−2 −0.5
10−3 −2 −1.0
10 10−1 100 101
ωτ0
A secondary logarithmic y axis can be drawn like this:
import graph;
size(9cm,6cm,IgnoreAspect);
string data="secondaryaxis.csv";
file in=line(csv(input(data)));
string[] titlelabel=in;
string[] columnlabel=in;
real[][] a=dimension(in,0,0);
a=transpose(a);
real[] t=a[0], susceptible=a[1], infectious=a[2], dead=a[3], larvae=a[4];
real[] susceptibleM=a[5], exposed=a[6],infectiousM=a[7];
scale(true);
xaxis("Time ($\tau$)",BottomTop,LeftTicks);
yaxis(Left,RightTicks);
scale(pic,Linear(true),Log(true));
draw(pic,graph(pic,t,infectious,t >= 10 & t <= 15),red);
yaxis(pic,Right,red,LeftTicks(begin=false,end=false));
});
add(secondary);
label(shift(5mm*N)*"Proportion of crows",point(NW),E);
Proportion of crows
0.9 100
0.7
0.5 10−1
0.3
0.1 10−2
10 11 12 13 14 15
Time (τ )
import graph;
import stats;
size(400,200,IgnoreAspect);
int n=10000;
real[] a=new real[n];
for(int i=0; i < n; ++i) a[i]=Gaussrand();
draw(graph(Gaussian,min(a),max(a)),blue);
histogram(a,min(a),max(a),N,normalize=true,low=0,lightred,black,bars=false);
xaxis("$x$",BottomTop,LeftTicks);
yaxis("$dP/dx$",LeftRight,RightTicks(trailingzero));
Chapter 7: Base modules 116
0.4
dP/dx 0.3
0.2
0.1
0.0
−3 −2 −1 0 1 2 3
x
11. Here is an example of reading column data in from a file and a least-squares fit, using
the stats module.
size(400,200,IgnoreAspect);
import graph;
import stats;
file fin=line(input("leastsquares.dat"));
real[][] a=dimension(fin,0,0);
a=transpose(a);
real first=100;
real step=50;
real last=700;
scale(Log(true),Linear(true));
real[] T,xi,dxi;
Chapter 7: Base modules 117
T.push(first);
xi.push(L.m);
dxi.push(L.dm);
}
draw(graph(T,xi),blue);
errorbars(T,xi,dxi,red);
crop();
ylimits(0);
xaxis("$T$",BottomTop,LeftTicks);
yaxis("$\xi$",LeftRight,RightTicks);
0 2
10 103
T
12. Here is an example that illustrates the general axis routine.
import graph;
size(0,100);
path g=ellipse((0,0),1,2);
Chapter 7: Base modules 118
scale(true);
axis(Label("C",align=10W),g,LeftTicks(endlabel=false,8,end=false),
ticklocate(0,360,new real(real v) {
path h=(0,0)--max(abs(max(g)),abs(min(g)))*dir(v);
return intersect(g,h)[0];}));
90
135 45
C 180 0
225 315
270
13. To draw a vector field of n arrows evenly spaced along the arclength of a path, use the
routine
picture vectorfield(path vector(real), path g, int n, bool truesize=false,
pen p=currentpen, arrowbar arrow=Arrow);
as illustrated in this simple example of a flow field:
import graph;
defaultpen(1.0);
size(0,150,IgnoreAspect);
real arrowsize=4mm;
real arrowlength=2arrowsize;
real epsilon=0.5;
path g=graph(f,epsilon,1/epsilon);
int n=3;
draw(g);
xaxis("$x$");
Chapter 7: Base modules 119
yaxis("$y$");
add(vectorfield(vector(W,W),g,n,true));
add(vectorfield(vector(NE,NW),(0,0)--(point(E).x,0),n,true));
add(vectorfield(vector(NE,NE),(0,0)--(0,point(N).y),n,true));
x
14. To draw a vector field of nx×ny arrows in box(a,b), use the routine
picture vectorfield(path vector(pair), pair a, pair b,
int nx=nmesh, int ny=nx, bool truesize=false,
real maxlength=truesize ? 0 : maxlength(a,b,nx,ny),
bool cond(pair z)=null, pen p=currentpen,
arrowbar arrow=Arrow, margin margin=PenMargin)
as illustrated in this example:
import graph;
size(100);
pair a=(0,0);
pair b=(2pi,2pi);
add(vectorfield(vector,a,b));
15. The following scientific graphs, which illustrate many features of Asymptote’s graphics
Chapter 7: Base modules 120
routines, were generated from the examples diatom.asy and westnile.asy, using the
comma-separated data in diatom.csv and westnile.csv.
Chapter 7: Base modules 121
A B C
g)
in
tz
ue
(K
g
in
s
e
os
tz
g
st
to ria
in
ue
R
cy
he
tz
K
)
w
ei
ue
s auc
n
h)
ll
no
or
K
sa
ot
en . v
lm
it
ru
as
a
K
(R
(G
m
/e
on var
H
si
ri
a
si
a
ea
is
ra
le
os
cr ina
os
ut
el
tr
ne
ul
rm
p.
in
c
u
vi
cc
te
ri pu
m
sp
m
ot
fo
flo
s
ila ca
ei
os
cf
s
ra
la
on
he
er
ag a
el
a
ei
ri
ri
ri
nt
oe
oc
on
os
lla
ila
ila
na
et
ac
i
be
er
ag
ag
no
ha
ch
ul
st
Ta
Fr
Fr
Fr
A
C
A
A
A
0 2000
1998
1996
1992 1994
1990
1988
1986
1984 1982
100 1980
1978
sediment depth (cm)
1972
1970
1965
200
1961
1950 1942
300 1940
1920
1915
1888 1910
400 1763
1726
50 50 50 40 50 40 40 10 8
%
1.0
0.9 1. Estimate
0.8 3. Determine proportion of
Susceptible bird survival
birds surviving
0.7 desired bird
at end of season
survival for
0.6 next season
0.5 2. Read off
4. Calculate initial
0.4 required mosquito
0.3 proportional abundance
reduction in
0.2 mosquitoes
0.1
0.0
0 10 M2 20 M1 30 40
Initial no. of mosquitoes per bird (SM0 /NB0 )
Chapter 7: Base modules 122
7.28 palette
Asymptote can also generate color density images and palettes. The following palettes are
predefined in palette.asy:
pen[] Grayscale(int NColors=256)
a grayscale palette;
pen[] Rainbow(int NColors=32766)
a rainbow spectrum;
pen[] BWRainbow(int NColors=32761)
a rainbow spectrum tapering off to black/white at the ends;
pen[] BWRainbow2(int NColors=32761)
a double rainbow palette tapering off to black/white at the ends, with a linearly
scaled intensity.
pen[] Wheel(int NColors=32766)
a full color wheel palette;
pen[] Gradient(int NColors=256 ... pen[] p)
a palette varying linearly over the specified array of pens, using NColors in each
interpolation interval;
The function cmyk(pen[] Palette) may be used to convert any of these palettes to the
CMYK colorspace.
A color density plot using palette palette can be generated from a function f(x,y) and
added to a picture pic:
bounds image(picture pic=currentpicture, real f(real,real),
range range=Full, pair initial, pair final,
int nx=ngraph, int ny=nx, pen[] palette, bool antialias=false)
The function f will be sampled at nx and ny evenly spaced points over a rectangle defined
by the points initial and final, respecting the current graphical scaling of pic. The color
space is scaled according to the z axis scaling (see [automatic scaling], page 109). A bounds
structure for the function values is returned:
struct bounds {
real min;
real max;
// Possible tick intervals:
int[] divisor;
}
This information can be used for generating an optional palette bar. The palette color
space corresponds to a range of values specified by the argument range, which can be Full,
Automatic, or an explicit range Range(real min, real max). Here Full specifies a range
varying from the minimum to maximum values of the function over the sampling interval,
while Automatic selects "nice" limits. The example imagecontour.asy illustrates how
level sets (contour lines) can be drawn on a color density plot (see Section 7.36 [contour],
page 146).
A color density plot can also be generated from an explicit real[][] array data:
Chapter 7: Base modules 123
import graph;
import palette;
int n=256;
real ninv=2pi/n;
real[][] v=new real[n][n];
pen[] Palette=BWRainbow();
picture bar;
Chapter 7: Base modules 124
bounds range=image(v,(0,0),(1,1),Palette);
palette(bar,"$A$",range,(0,0),(0.5cm,8cm),Right,Palette,
PaletteTicks("$%+#.1f$"));
add(bar.fit(),point(E),30E);
+1.0
+0.8
+0.6
+0.4
+0.2
0.0 A
−0.2
−0.4
−0.6
−0.8
−1.0
size(10cm,10cm,IgnoreAspect);
scale(Linear,Log,Log);
pen[] Palette=BWRainbow();
bounds range=image(f,Automatic,(0,1),(100,100),nx=200,Palette);
xaxis("$x$",BottomTop,LeftTicks,above=true);
yaxis("$y$",LeftRight,RightTicks,above=true);
palette("$f(x,y)$",range,(0,200),(100,250),Top,Palette,
Chapter 7: Base modules 125
PaletteTicks(ptick=linewidth(0.5*linewidth())));
f (x, y)
10−3 10−2 10−1 100 101 102
102
y 101
100
0 20 40 60 80 100
x
One can also draw an image directly from a two-dimensional pen array:
void image(picture pic=currentpicture, pen[][] data,
pair initial, pair final,
bool transpose=(initial.x < final.x && initial.y < final.y),
bool copy=true, bool antialias=false);
as illustrated in the following example:
size(200);
import palette;
int n=256;
real ninv=2pi/n;
pen[][] v=new pen[n][n];
image(v,(0,0),(1,1));
Chapter 7: Base modules 126
For convenience, the module palette also defines functions that may be used to
construct a pen array from a given function and palette:
pen[] palette(real[] f, pen[] palette);
pen[][] palette(real[][] f, pen[] palette);
7.29 three
This module fully extends the notion of guides and paths in Asymptote to three dimensions.
It introduces the new types guide3, path3, and surface. Guides in three dimensions are
specified with the same syntax as in two dimensions except that triples (x,y,z) are used
in place of pairs (x,y) for the nodes and direction specifiers. This generalization of John
Hobby’s spline algorithm is shape-invariant under three-dimensional rotation, scaling, and
shifting, and reduces in the planar case to the two-dimensional algorithm used in Asymptote,
MetaPost, and MetaFont [cf. J. C. Bowman, Proceedings in Applied Mathematics and
Mechanics, 7:1, 2010021-2010022 (2007)].
For example, a unit circle in the XY plane may be filled and drawn like this:
import three;
size(100);
path3 g=(1,0,0)..(0,1,0)..(-1,0,0)..(0,-1,0)..cycle;
draw(g);
draw(O--Z,red+dashed,Arrow3);
draw(((-1,-1,0)--(1,-1,0)--(1,1,0)--(-1,1,0)--cycle));
dot(g,red);
size(100,0);
path3 g=(1,0,0)..(0,1,1)..(-1,0,0)..(0,-1,1)..cycle;
draw(g);
draw(((-1,-1,0)--(1,-1,0)--(1,1,0)--(-1,1,0)--cycle));
dot(g,red);
support vertex shading of Bezier surfaces, PRC patches are shaded with the mean of the
four vertex colors.
A surface can be constructed from a cyclic path3 with the constructor
surface surface(path3 external, triple[] internal=new triple[],
triple[] normals=new triple[], pen[] colors=new pen[],
bool3 planar=default);
and then filled:
draw(surface(path3(polygon(5))),red,nolight);
draw(surface(unitcircle3),red,nolight);
draw(surface(unitcircle3,new pen[] {red,green,blue,black}),nolight);
The last example constructs a patch with vertex-specific colors. A three-dimensional planar
surface in the plane plane can be constructed from a two-dimensional cyclic path g with
the constructor
surface surface(path p, triple plane(pair)=XYplane);
and then filled:
draw(surface((0,0)--E+2N--2E--E+N..0.2E..cycle),red);
Planar Bezier surfaces patches are constructed using Orest Shardt’s bezulate routine, which
decomposes (possibly nonsimply connected) regions bounded by nonselfintersecting cyclic
paths (according to the zerowinding fill rule) into subregions bounded by cyclic paths of
length 4 or less.
Arbitrary thick three-dimensional curves and line caps (which the OpenGL standard does
not require implementations to provide) are constructed with the routine
surface tube(path3 g, real width);
which returns a tube of diameter width centered on g. This can make files slow to render,
especially with the Adobe Reader renderer. The setting thick=false can be used to disable
this feature and force all lines to be drawn with linewidth(0) (one pixel wide, regardless
of the resolution). By default mesh and contour lines in three-dimensions are always drawn
thin, unless an explicit line width is given in the pen parameter or the setting thin is set
to false. The pens thin() and thick() defined in plain pens.asy can also be used to
override these defaults for specific draw commands.
There are four choices for viewing 3D Asymptote output:
1. Use the native Asymptote adaptive OpenGL-based renderer (with the command-line
option -V and the default settings outformat="" and render=-1). If you encounter
warnings from your graphics card driver, try specifying -glOptions=-indirect on
the command line. On UNIX systems with graphics support for multisampling, we
recommend installing the latest SVN (antialiased) version of the freeglut library
(see [multisampling], page 6); the sample width can be controlled with the setting
multisample. An initial screen position can be specified with the pair setting
position, where negative values are interpreted as relative to the corresponding
maximum screen dimension. The default settings
import settings;
leftbutton=new string[] {"rotate","zoom","shift","pan"};
middlebutton=new string[] {"menu"};
Chapter 7: Base modules 129
efficient by increasing the maximum tile size maxtile beyond the screen dimensions
(indicated by maxtile=(0,0). The tile size is also limited by the setting maxviewport,
which restricts the maximum width and height of the viewport. On UNIX systems
some graphics drivers support batch mode (-noV) rendering in an iconified window;
this can be enabled with the setting iconify=true. Some (broken) UNIX graphics
drivers may require the command line setting -glOptions=-indirect, which requests
(slower) indirect rendering.
3. Embed the 3D PRC format in a PDF file and view the resulting PDF file with version
8.0 or later of Adobe Reader. In addition to the default settings.prc=true,
this requires settings.outformat="pdf", which can be specified by the command
line option -f pdf, put in the Asymptote configuration file (see [configuration
file], page 154), or specified in the script before three.asy (or graph3.asy) is
imported. Version 2008/10/08 or later of the movie15 package is also required
(see Section 7.17 [embed], page 91). The example pdb.asy illustrates how one
can generate a list of predefined views (see 100d.views). A stationary preview
image with a resolution of n pixels per bp can be embedded with the setting
render=n; this allows the file to be viewed with other PDF viewers. Alternatively,
the file externalprc.tex illustrates how the resulting PRC and rendered image
files can be extracted and processed in a separate LaTeX file. However, see
Chapter 6 [LaTeX usage], page 81 for an easier way to embed three-dimensional
Asymptote pictures within LaTeX. The open-source PRC specification is available
from http://livedocs.adobe.com/acrobat_sdk/9/Acrobat9_HTMLHelp/API_
References/PRCReference/PRC_Format_Specification/.
4. Project the scene to a two-dimensional vector (EPS or PDF) format with render=0.
Only limited hidden surface removal facilities are currently available with this approach
(see [PostScript3D], page 135).
Automatic picture sizing in three dimensions is accomplished with double deferred
drawing. The maximal desired dimensions of the scene in each of the three dimensions
can optionally be specified with the routine
void size3(picture pic=currentpicture, real x, real y=x, real z=y,
bool keepAspect=pic.keepAspect);
The resulting simplex linear programming problem is then solved to produce a 3D version
of a frame (actually implemented as a 3D picture). The result is then fit with another
application of deferred drawing to the viewport dimensions corresponding to the usual two-
dimensional picture size parameters. The global pair viewportmargin may be used to
add horizontal and vertical margins to the viewport dimensions. Alternatively, a minimum
viewportsize may be specified.
For convenience, the three module defines O=(0,0,0), X=(1,0,0), Y=(0,1,0), and
Z=(0,0,1), along with a unitcircle in the XY plane:
path3 unitcircle3=X..Y..-X..-Y..cycle;
A general (approximate) circle can be drawn perpendicular to the direction normal with
the routine
path3 circle(triple c, real r, triple normal=Z);
A circular arc centered at c with radius r from c+r*dir(theta1,phi1) to
c+r*dir(theta2,phi2), drawing counterclockwise relative to the normal vector
Chapter 7: Base modules 131
if possible, the vector up points upwards. Parallel lines are projected to parallel
lines. The bounding volume is expanded to include target if showtarget=true.
If center=true, the target will be adjusted to the center of the bounding
volume.
orthographic(real x, real y, real z, triple up=Z, triple target=O,
real zoom=1, pair viewportshift=0, bool showtarget=true,
bool center=false)
This is equivalent to
orthographic((x,y,z),up,target,zoom,viewportshift,showtarget,center)
perspective(triple camera, triple up=Z, triple target=O,
real zoom=1, real angle=0, pair viewportshift=0,
bool showtarget=true, bool autoadjust=true,
bool center=autoadjust)
This projects from three to two dimensions, taking account of perspective,
as seen from the location camera looking at target, orienting the
camera so that, if possible, the vector up points upwards. If render=0,
projection of three-dimensional cubic Bezier splines is implemented by
approximating a two-dimensional nonuniform rational B-spline (NURBS) with
a two-dimensional Bezier curve containing additional nodes and control points.
If autoadjust=true, the camera will automatically be adjusted to lie outside
the bounding volume for all possible interactive rotations about target.
If center=true, the target will be adjusted to the center of the bounding
volume.
perspective(real x, real y, real z, triple up=Z, triple target=O,
real zoom=1, real angle=0, pair viewportshift=0,
bool showtarget=true, bool autoadjust=true,
bool center=autoadjust)
This is equivalent to
perspective((x,y,z),up,target,zoom,angle,viewportshift,showtarget,
autoadjust,center)
The default projection, currentprojection, is initially set to perspective(5,4,2).
We also define standard orthographic views used in technical drawing:
projection LeftView=orthographic(-X,showtarget=true);
projection RightView=orthographic(X,showtarget=true);
projection FrontView=orthographic(-Y,showtarget=true);
projection BackView=orthographic(Y,showtarget=true);
projection BottomView=orthographic(-Z,showtarget=true);
projection TopView=orthographic(Z,showtarget=true);
The function
void addViews(picture dest=currentpicture, picture src, bool group=true,
filltype filltype=NoFill);
adds picture pic as seen with FrontView aligned above the projection TopView and to the
right of the projection RightView. Alternatively, the function
Chapter 7: Base modules 133
argument projection P=currentprojection that rotate and/or flip the label so that it is
more readable from the initial viewpoint.
A transform3 that projects in the direction dir onto the plane with normal n through
point O is returned by
transform3 planeproject(triple n, triple O=O, triple dir=n);
One can use
triple normal(path3 p);
to find the unit normal vector to a planar three-dimensional path p. As illustrated in the
example planeproject.asy, a transform3 that projects in the direction dir onto the plane
defined by a planar path p is returned by
transform3 planeproject(path3 p, triple dir=normal(p));
The functions
surface extrude(path p, triple axis=Z);
surface extrude(Label L, triple axis=Z);
return the surface obtained by extruding path p or Label L along axis.
Three-dimensional versions of the path functions length, size, point, dir, accel,
radius, precontrol, postcontrol, arclength, arctime, reverse, subpath, intersect,
intersections, intersectionpoint, intersectionpoints, min, max, cyclic, and
straight are also defined.
The routine
real[][] intersections(path3 p, surface s, real fuzz=-1);
returns the intersection times of a path p with a surface s as a sorted array of real arrays
of length 2, and
triple[] intersectionpoints(path3 p, surface s, real fuzz=-1);
returns the corresponding intersection points. Here, the computations are performed to the
absolute error specified by fuzz, or if fuzz < 0, to machine precision.
Here is an example showing all five guide3 connectors:
import graph3;
size(200);
currentprojection=orthographic(500,-500,500);
path3 p=z[0]..z[1]---z[2]::{Y}z[3]
&z[3]..z[4]--z[5]::{Y}z[6]
&z[6]::z[7]---z[8]..{Y}z[9];
Chapter 7: Base modules 135
draw(p,grey+linewidth(4mm)+opacity(0.5));
xaxis3(Label(XY()*"$x$",align=-3Y),red,above=true);
yaxis3(Label(XY()*"$y$",align=-3X),red,above=true);
dot(z);
Three-dimensional versions of bars or arrows can be drawn with one of the specifiers
None, Blank, BeginBar3, EndBar3 (or equivalently Bar3), Bars3, BeginArrow3, MidArrow3,
EndArrow3 (or equivalently Arrow3), Arrows3, BeginArcArrow3, EndArcArrow3 (or
equivalently ArcArrow3), MidArcArrow3, and ArcArrows3. Three-dimensional bars accept
the optional arguments (real size=0, triple dir=O). If size=O, the default bar length is
used; if dir=O, the bar is drawn perpendicular to the path and the initial viewing direction.
The predefined three-dimensional arrowhead styles are DefaultHead3, HookHead3,
TeXHead3. Versions of the two-dimensional arrowheads lifted to three-dimensional space
and aligned according to the initial viewpoint (or an optionally specified normal vector)
are also defined: DefaultHead2(triple normal=O), HookHead2(triple normal=O),
TeXHead2(triple normal=O). These are illustrated in the example arrows3.asy.
Module three also defines the three-dimensional margins NoMargin3, BeginMargin3,
EndMargin3, Margin3, Margins3, BeginPenMargin2, EndPenMargin2, PenMargin2,
PenMargins2, BeginPenMargin3, EndPenMargin3, PenMargin3, PenMargins3,
BeginDotMargin3, EndDotMargin3, DotMargin3, DotMargins3, Margin3, and
TrueMargin3.
Further three-dimensional examples are provided in the files near_earth.asy,
conicurv.asy, and (in the animations subdirectory) cube.asy.
Limited support for projected vector graphics (effectively three-dimensional nonrendered
PostScript) is available with the setting render=0. This currently only works for piecewise
planar surfaces, such as those produced by the parametric surface routines in the graph3
module. Surfaces produced by the solids package will also be properly rendered if the
parameter nslices is sufficiently large.
In the module bsp, hidden surface removal of planar pictures is implemented using a
binary space partition and picture clipping. A planar path is first converted to a structure
face derived from picture. A face may be given to a two-dimensional drawing routine
Chapter 7: Base modules 136
in place of any picture argument. An array of such faces may then be drawn, removing
hidden surfaces:
void add(picture pic=currentpicture, face[] faces,
projection P=currentprojection);
Labels may be projected to two dimensions, using projection P, onto the plane passing
through point O with normal cross(u,v) by multiplying it on the left by the transform
transform transform(triple u, triple v, triple O=O,
projection P=currentprojection);
Here is an example that shows how a binary space partition may be used to draw a
two-dimensional vector graphics projection of three orthogonal intersecting planes:
size(6cm,0);
import bsp;
real u=2.5;
real v=1;
currentprojection=oblique;
path3 y=plane((2u,0,0),(0,2v,0),(-u,-v,0));
path3 l=rotate(90,Z)*rotate(90,Y)*y;
path3 g=rotate(90,X)*rotate(90,Y)*y;
face[] faces;
filldraw(faces.push(y),project(y),yellow);
filldraw(faces.push(l),project(l),lightgrey);
filldraw(faces.push(g),project(g),green);
add(faces);
Chapter 7: Base modules 137
7.30 obj
This module allows one to construct surfaces from simple obj files, as illustrated in the
example files galleon.asy and triceratops.asy.
7.31 graph3
This module implements three-dimensional versions of the functions in graph.asy. To draw
an x axis in three dimensions, use the routine
void xaxis3(picture pic=currentpicture, Label L="", axis axis=YZZero,
real xmin=-infinity, real xmax=infinity, pen p=currentpen,
ticks3 ticks=NoTicks3, arrowbar3 arrow=None, bool above=false);
Analogous routines yaxis and zaxis can be used to draw y and z axes in three dimensions.
There is also a routine for drawing all three axis:
void axes3(picture pic=currentpicture,
Label xlabel="", Label ylabel="", Label zlabel="",
triple min=(-infinity,-infinity,-infinity),
triple max=(infinity,infinity,infinity),
pen p=currentpen, arrowbar3 arrow=None);
The predefined three-dimensional axis types are
axis YZEquals(real y, real z, triple align=O, bool extend=false);
axis XZEquals(real x, real z, triple align=O, bool extend=false);
axis XYEquals(real x, real y, triple align=O, bool extend=false);
axis YZZero(triple align=O, bool extend=false);
axis XZZero(triple align=O, bool extend=false);
axis XYZero(triple align=O, bool extend=false);
axis Bounds(int type=Both, int type2=Both, triple align=O, bool extend=false);
The optional align parameter to these routines can be used to specify the default axis
and tick label alignments. The Bounds axis accepts two type parameters, each of which
must be one of Min, Max, or Both. These parameters specify which of the four possible
three-dimensional bounding box edges should be drawn.
The three-dimensional tick options are NoTicks3, InTicks, OutTicks, and InOutTicks.
These specify the tick directions for the Bounds axis type; other axis types inherit the
direction that would be used for the Bounds(Min,Min) axis.
Here is an example of a helix and bounding box axes with ticks and axis labels, using
orthographic projection:
import graph3;
size(0,200);
size3(200,IgnoreAspect);
currentprojection=orthographic(4,6,3);
draw(p,Arrow3);
scale(true);
xaxis3(XZ()*"$x$",Bounds,red,InTicks(Label,2,2));
yaxis3(YZ()*"$y$",Bounds,red,InTicks(beginlabel=false,Label,2,2));
zaxis3(XZ()*"$z$",Bounds,red,InTicks);
import graph3;
size(0,200);
size3(200,IgnoreAspect);
currentprojection=perspective(5,2,2);
scale(Linear,Linear,Log);
xaxis3("$x$",0,1,red,OutTicks(2,2));
yaxis3("$y$",0,1,red,OutTicks(2,2));
zaxis3("$z$",1,30,red,OutTicks(beginlabel=false));
Chapter 7: Base modules 139
size(0,100);
path3 g=yscale3(2)*unitcircle3;
currentprojection=perspective(10,10,10);
axis(Label("C",position=0,align=15X),g,InTicks(endlabel=false,8,end=false),
ticklocate(0,360,new real(real v) {
path3 h=O--max(abs(max(g)),abs(min(g)))*dir(90,v);
return intersect(g,h)[0];},
new triple(real t) {return cross(dir(g,t),Z);}));
Surface plots of matrices and functions over the region box(a,b) in the XY plane are
also implemented:
surface surface(real[][] f, pair a, pair b, bool[][] cond={});
surface surface(real[][] f, pair a, pair b, splinetype xsplinetype,
splinetype ysplinetype=xsplinetype, bool[][] cond={});
surface surface(real[][] f, real[] x, real[] y,
splinetype xsplinetype=null, splinetype ysplinetype=xsplinetype,
bool[][] cond={})
surface surface(triple[][] f, bool[][] cond={});
surface surface(real f(pair z), pair a, pair b, int nx=nmesh, int ny=nx,
Chapter 7: Base modules 140
The final two versions draw parametric surfaces for a function f (u, v) over the parameter
space box(a,b), as illustrated in the example parametricsurface.asy. An optional
splinetype Spline may be specified. The boolean array or function cond can be used to
control which surface mesh cells are actually drawn (by default all mesh cells over box(a,b)
are drawn). Surface lighting is illustrated in the example files parametricsurface.asy
and sinc.asy. Lighting can be disabled by setting light=nolight, as in this example of a
Gaussian surface:
import graph3;
size(200,0);
currentprojection=perspective(10,8,4);
draw((-1,-1,0)--(1,-1,0)--(1,1,0)--(-1,1,0)--cycle);
draw(arc(0.12Z,0.2,90,60,90,25),ArcArrow3);
surface s=surface(f,(-1,-1),(1,1),nx=5,Spline);
xaxis3(Label("$x$"),red,Arrow3);
yaxis3(Label("$y$"),red,Arrow3);
zaxis3(XYZero(extend=true),red,Arrow3);
draw(s,lightgray,meshpen=black+thick(),nolight);
label("$O$",O,-Z+Y,red);
Chapter 7: Base modules 141
A mesh can be drawn without surface filling by specifying nullpen for the surfacepen.
A vector field of nu×nv arrows on a parametric surface f over box(a,b) can be drawn
with the routine
7.32 grid3
This module, contributed by Philippe Ivaldi, can be used for drawing 3D
grids. Here is an example (further examples can be found in grid3.asy and at
http://piprim.tuxfamily.org/asymptote/grid3/):
import grid3;
size(8cm,0,IgnoreAspect);
currentprojection=orthographic(0.5,1,0.5);
limits((-2,-2,1),(0,2,100));
grid3(XYZgrid);
xaxis3(Label("$x$",position=EndPoint,align=S),Bounds(Min,Min),
OutTicks());
yaxis3(Label("$y$",position=EndPoint,align=S),Bounds(Min,Min),OutTicks());
zaxis3(Label("$z$",position=EndPoint,align=(-1,0.5)),Bounds(Min,Min),
OutTicks(beginlabel=false));
Chapter 7: Base modules 142
7.33 solids
This solid geometry package defines a structure revolution that can be used to fill and
draw surfaces of revolution. The following example uses it to display the outline of a circular
cylinder of radius 1 with axis O--1.5unit(Y+Z) with perspective projection:
import solids;
size(0,100);
revolution r=cylinder(O,1,1.5,Y+Z);
draw(r,heavygreen);
path3[] back;
}
// transverse skeleton (perpendicular to axis of revolution)
curve transverse;
// longitudinal skeleton (parallel to axis of revolution)
curve longitudinal;
}
7.34 tube
This package extends the routine tube defined in three_arrows.asy to arbitrary cross
sections, colors, and spine transformations. The routine
surface tube(path3 g, coloredpath section,
transform T(real)=new transform(real t) {return identity();},
real corner=1, real relstep=0);
draws a tube along g with cross section section, after applying the transformation T(t)
at relpoint(g,t). The parameter corner controls the number of elementary tubes at the
angular points of g. A nonzero value of relstep specifies a fixed relative time step (in
the sense of relpoint(g,t)) to use in constructing elementary tubes along g. The type
coloredpath is a generalization of path to which a path can be cast:
struct coloredpath
{
path p;
pen[] pens(real);
int colortype=coloredSegments;
}
Here p defines the cross section and the method pens(real t) returns an array of pens
(interpreted as a cyclic array) used for shading the tube patches at relpoint(g,t). If
colortype=coloredSegments, the tube patches are filled as if each segment of the section
was colored with the pen returned by pens(t), whereas if colortype=coloredNodes, the
tube components are vertex shaded as if the nodes of the section were colored.
A coloredpath can be constructed with one of the routines:
coloredpath coloredpath(path p, pen[] pens(real),
int colortype=coloredSegments);
coloredpath coloredpath(path p, pen[] pens=new pen[] {currentpen},
int colortype=coloredSegments);
coloredpath coloredpath(path p, pen pen(real));
In the second case, the pens are independent of the relative time. In the third case, the
array of pens contains only one pen, which depends of the relative time.
The casting of path to coloredpath allows the use of a path instead of a coloredpath;
in this case the shading behaviour is the default shading behavior for a surface.
An example of tube is provided in the file trefoilknot.asy. Further examples can be
found at http://piprim.tuxfamily.org/asymptote/tube/.
Chapter 7: Base modules 144
7.35 flowchart
This package provides routines for drawing flowcharts. The primary structure is a block,
which represents a single block on the flowchart. The following eight functions return a
position on the appropriate edge of the block, given picture transform t:
pair block.top(transform t=identity());
pair block.left(transform t=identity());
pair block.right(transform t=identity());
pair block.bottom(transform t=identity());
pair block.topleft(transform t=identity());
pair block.topright(transform t=identity());
pair block.bottomleft(transform t=identity());
pair block.bottomright(transform t=identity());
To obtain an arbitrary position along the boundary of the block in user coordinates, use:
pair block.position(real x, transform t=identity());
The center of the block in user coordinates is stored in block.center and the block size in
PostScript coordinates is given by block.size.
A frame containing the block is returned by
frame block.draw(pen p=currentpen);
The following block generation routines accept a Label, string, or frame for their object
argument:
rectangular block with an optional header (and padding dx around header and body):
block rectangle(object header, object body, pair center=(0,0),
pen headerpen=mediumgray, pen bodypen=invisible,
pen drawpen=currentpen,
real dx=3, real minheaderwidth=minblockwidth,
real minheaderheight=minblockwidth,
real minbodywidth=minblockheight,
real minbodyheight=minblockheight);
block rectangle(object body, pair center=(0,0),
pen fillpen=invisible, pen drawpen=currentpen,
real dx=3, real minwidth=minblockwidth,
real minheight=minblockheight);
diamond-shaped flowchart block:
block diamond(object body, pair center=(0,0),
pen fillpen=invisible, pen drawpen=currentpen,
real ds=5, real dw=1,
real height=20, real minwidth=minblockwidth,
real minheight=minblockheight);
circular flowchart block:
block circle(object body, pair center=(0,0), pen fillpen=invisible,
pen drawpen=currentpen, real dr=3,
real mindiameter=mincirclediameter);
rectangular flowchart block with rounded corners:
block roundrectangle(object body, pair center=(0,0),
Chapter 7: Base modules 145
To draw paths joining the pairs in point with right-angled lines, use the routine:
The entries in dir identify whether successive segments between the pairs specified by point
should be drawn in the Horizontal or Vertical direction.
size(0,300);
import flowchart;
block block1=rectangle(Label("Example",magenta),
pack(Label("Start:",heavygreen),"",Label("$A:=0$",blue),
"$B:=1$"),(-0.5,3),palegreen,paleblue,red);
block block2=diamond(Label("Choice?",blue),(0,2),palegreen,red);
block block3=roundrectangle("Do something",(-1,1));
block block4=bevel("Don’t do something",(1,1));
block block5=circle("End",(0,0));
draw(block1);
draw(block2);
draw(block3);
draw(block4);
draw(block5);
Example
Start:
A := 0
B := 1
Yes No
Choice?
End
7.36 contour
This package draws contour lines. To construct contours corresponding to the values in an
array c for a function f on box(a,b), use
guide[][] contour(real f(real, real), pair a, pair b,
real[] c, int nx=ngraph, int ny=nx,
interpolate join=operator --);
The integers nx and ny define the resolution. The default resolution, ngraph x ngraph
(here ngraph defaults to 100), can be increased for greater accuracy. The default
interpolation operator is operator -- (linear). Spline interpolation (operator ..) may
produce smoother contours but it can also lead to overshooting.
To construct contours for an array of data values on a uniform two-dimensional lattice
on box(a,b), use
guide[][] contour(real[][] f, real[][] midpoint=new real[][],
pair a, pair b, real[] c,
interpolate join=operator --);
To construct contours for an array of data values on a nonoverlapping regular mesh
specified by the two-dimensional array z, optionally specifying the values of f at the mesh
midpoints, use
guide[][] contour(pair[][] z, real[][] f,
real[][] midpoint=new real[][], real[] c,
interpolate join=operator --);
Chapter 7: Base modules 147
The next example draws and labels multiple contours for the function z = x2 − y 2 with
the resolution 100 x 100, using a dashed pen for negative contours and a solid pen for
positive (and zero) contours:
import contour;
size(200);
draw(Labels,contour(f,(-1,-1),(1,1),c),p);
-0.1 -0.5
-0.3
-0.2
-0.4
0.2
0.3
0.1
0.4
0.4
0.1
0.3
0.2
-0.4
-0.2
-0.3
-0.1 -0.5
The next example illustrates how contour lines can be drawn on color density images:
import graph;
import palette;
import contour;
size(10cm,10cm,IgnoreAspect);
pair a=(0,0);
pair b=(2pi,2pi);
int N=200;
int Divs=10;
int divs=2;
defaultpen(1bp);
pen Tickpen=black;
pen tickpen=gray+0.5*linewidth(currentpen);
pen[] Palette=BWRainbow();
scale(false);
bounds range=image(f,Automatic,a,b,N,Palette);
// Major contours
real[] Cvals=uniform(range.min,range.max,Divs);
draw(contour(f,a,b,Cvals,N,operator --),Tickpen);
Chapter 7: Base modules 149
// Minor contours
real[] cvals;
for(int i=0; i < Cvals.length-1; ++i)
cvals.append(uniform(Cvals[i],Cvals[i+1],divs)[1:divs]);
draw(contour(f,a,b,cvals,N,operator --),tickpen);
xaxis("$x$",BottomTop,LeftTicks,above=true);
yaxis("$y$",LeftRight,RightTicks,above=true);
palette("$f(x,y)$",range,point(NW)+(0,0.5),point(NE)+(0,1),Top,Palette,
PaletteTicks(N=Divs,n=divs,Tickpen,tickpen));
f (x, y)
−1 −0.8 −0.6 −0.4 −0.2 0 0.2 0.4 0.6 0.8 1
4
y
3
0
0 1 2 3 4 5 6
x
Finally, here is an example that illustrates the construction of contours from irregularly
spaced data:
import contour;
size(200);
int n=100;
In the above example, the contours of irregularly spaced data are constructed by first
creating a triangular mesh from an array z of pairs:
int[][] triangulate(pair[] z);
size(200);
int np=100;
pair[] points;
int[][] trn=triangulate(points);
The example Gouraudcontour illustrates how to produce color density images over such
irregular triangular meshes. Asymptote uses a robust version of Paul Bourke’s Delaunay
triangulation algorithm based on the public-domain exact arithmetic predicates written by
Jonathan Shewchuk.
7.37 contour3
This package draws surfaces described as the null space of real-valued functions of (x, y, z)
or real[][][] matrices. Its usage is illustrated in the example file magnetic.asy.
7.38 slopefield
To draw a slope field for the differential equation dy/dx = f (x, y) (or dy/dx = f (x)), use:
picture slopefield(real f(real,real), pair a, pair b,
int nx=nmesh, int ny=nx,
real tickfactor=0.5, pen p=currentpen,
arrowbar arrow=None);
Here, the points a and b are the lower left and upper right corners of the rectangle in which
the slope field is to be drawn, nx and ny are the respective number of ticks in the x and
y directions, tickfactor is the fraction of the minimum cell dimension to use for drawing
ticks, and p is the pen to use for drawing the slope fields. The return value is a picture that
can be added to currentpicture via the add(picture) command.
The function
path curve(pair c, real f(real,real), pair a, pair b);
takes a point (c) and a slope field-defining function f and returns, as a path, the curve
passing through that point. The points a and b represent the rectangular boundaries over
which the curve is interpolated.
Chapter 7: Base modules 152
Both slopefield and curve alternatively accept a function real f(real) that depends
on x only, as seen in this example:
import slopefield;
size(200);
7.39 ode
The ode module, illustrated in the example odetest.asy, implements a number of explicit
numerical integration schemes for ordinary differential equations.
Chapter 8: Options 153
8 Options
Type asy -h to see the full list of command-line options supported by Asymptote:
Usage: ../asy [options] [file ...]
option). Asymptote will look for this file in its usual search path. Typically the configuration
file is placed in the .asy directory in the user’s home directory (%USERPROFILE%\.asy under
MSDOS). Configuration variables are accessed using the long form of the option names:
import settings;
outformat="pdf";
batchView=false;
interactiveView=true;
batchMask=false;
interactiveMask=true;
Command-line options override these defaults. Most configuration variables may
also be changed at runtime. The advanced configuration variables dvipsOptions,
convertOptions, gsOptions, psviewerOptions, pdfviewerOptions, and glOptions
allow specialized options to be passed as a string to the respective applications or libraries.
If you insert
import plain;
settings.autoplain=true;
at the beginning of the configuration file, it can contain arbitrary Asymptote code.
The default output format is EPS for the (default) latex and tex tex engine and
PDF for the pdflatex, xelatex, and context tex engines. Alternative output formats
may be produced using the -f option (or outformat setting). The optional setting -
render n requests an output resolution of n pixels per bp. Antialiasing is controlled by the
parameter antialias, which by default specifies a sampling width of 2 pixels. Asymptote
can produce any output format supported by the ImageMagick convert program (version
6.3.5 or later recommended; an Invalid Parameter error message indicates that the MSDOS
utility convert is being used instead of the one that comes with ImageMagick). To give
specific options to convert, use the convertOptions setting or call convert manually. This
example emulates how Asymptote produces antialiased tiff output at one pixel per bp:
asy -o - venn | convert -alpha Off -density 144x144 -geometry 50%x eps:- venn.tiff
If the option -nosafe is given, Asymptote runs in unsafe mode. This enables the int
system(string s) and int system(string[] s) calls, allowing one to execute arbitrary
shell commands. The default mode, -safe, disables this call.
A PostScript offset may be specified as a pair (in bp units) with the -O option:
asy -O 0,0 file
The default offset is zero. The default value of the page alignment setting align is Center.
The -c (command) option may be used to execute arbitrary Asymptote code on the
command line as a string. It is not necessary to terminate the string with a semicolon.
Multiple -c options are executed in the order they are given. For example
asy -c 2+2 -c "sin(1)" -c "size(100); draw(unitsquare)"
produces the output
4
0.841470984807897
and draws a unitsquare of size 100.
Chapter 8: Options 156
The -u (user) option may be used to specify arbitrary Asymptote settings on the
command line as a string. It is not necessary to terminate the string with a semicolon.
Multiple -u options are executed in the order they are given. Command-line code like -u
x=sqrt(2) can be executed within a module like this:
real x;
usersetting();
write(x);
When the -l (listvariables) option is used with file arguments, only global functions
and variables defined in the specified file(s) are listed.
Additional debugging output is produced with each additional -v option:
-v Display top-level module and final output file names.
-vv Also display imported and included module names and final LaTeX and dvips
processing information.
-vvv Also output LaTeX bidirectional pipe diagnostics.
-vvvv Also output knot guide solver diagnostics.
-vvvvv Also output Asymptote traceback diagnostics.
Chapter 9: Interactive mode 157
9 Interactive mode
Interactive mode is entered by executing the command asy with no file arguments. When
the -multiline option is disabled (the default), each line must be a complete Asymptote
statement (unless explicitly continued by a final backslash character \); it is not necessary
to terminate input lines with a semicolon. If one assigns settings.multiline=true,
interactive code can be entered over multiple lines; in this mode, the automatic termination
of interactive input lines by a semicolon is inhibited. Multiline mode is useful for cutting
and pasting Asymptote code directly into the interactive input buffer.
Interactive mode can be conveniently used as a calculator: expressions entered at the
interactive prompt (for which a corresponding write function exists) are automatically
evaluated and written to stdout.
The following special commands are supported only in interactive mode and must be
entered immediately after the prompt:
help view the manual;
reset reset the Asymptote environment to its initial state, except for changes to
the settings module (see [settings], page 154), the current directory (see [cd],
page 51), and breakpoints (see Chapter 13 [Debugger], page 162);
input FILE
does an interactive reset, followed by the command include FILE. If the
file name FILE contains nonalphanumeric characters, enclose it with quotation
marks. A trailing semi-colon followed by optional Asymptote commands may
be entered on the same line.
quit exit interactive mode (exit is a synonym; the abbreviation q is also accepted
unless there exists a top-level variable named q). A history of the most recent
1000 (this number can be changed with the historylines configuration
variable) previous commands will be retained in the file .asy/history in the
user’s home directory (unless the command-line option -localhistory was
specified, in which case the history will be stored in the file .asy_history in
the current directory).
Typing ctrl-C interrupts the execution of Asymptote code and returns control to the
interactive prompt.
Interactive mode is implemented with the GNU readline library, with
command history and auto-completion. To customize the key bindings, see:
http://cnswww.cns.cwru.edu/php/chet/readline/readline.html
The file asymptote.py in the Asymptote system directory provides an alternative way of
entering Asymptote commands interactively, coupled with the full power of Python. Copy
this file to your Python path and then execute from within Python the commands
from asymptote import *
g=asy()
g.size(200)
g.draw("unitcircle")
g.send("draw(unitsquare)")
Chapter 9: Interactive mode 158
g.fill("unitsquare, blue")
g.clip("unitcircle")
g.label("\"$O$\", (0,0), SW")
Chapter 10: Graphical User Interface 159
11 PostScript to Asymptote
The excellent PostScript editor pstoedit (version 3.45 or later; available from
http://pstoedit.net) includes an Asymptote backend. Unlike virtually all other
pstoedit backends, this driver includes native clipping, even-odd fill rule, PostScript
subpath, and full image support.
For full functionality, the patch pstoedit-3.45asy.patch in the patches directory
should be applied. On UNIX systems, as the root user, place
http://prdownloads.sourceforge.net/pstoedit/pstoedit-3.45.tar.gz
in the Asymptote source directory, and type:
tar -zxf pstoedit-3.45.tar.gz
cd pstoedit-3.45
patch -p1 < ../patches/pstoedit-3.45asy.patch
autoconf
./configure --prefix=/usr
make install
Then try:
asy -V /usr/local/share/doc/asymptote/examples/venn.asy
pstoedit -f asy venn.eps test.asy
asy -V test
If the line widths aren’t quite correct, try giving pstoedit the -dis option. If the fonts
aren’t typeset correctly, try giving pstoedit the -dt option.
Chapter 12: Help 161
12 Help
A list of frequently asked questions (FAQ) is maintained at
http://asymptote.sourceforge.net/FAQ
Questions on installing and using Asymptote that are not addressed in the FAQ should be
sent to the Asymptote forum:
http://sourceforge.net/forum/forum.php?forum_id=409349
Including an example that illustrates what you are trying to do will help you get useful
feedback. LaTeX problems can often be diagnosed with the -vv or -vvv command-line
options. Contributions in the form of patches or Asymptote modules can be posted here:
http://sourceforge.net/tracker/?atid=685685&group_id=120000
To receive announcements of upcoming releases, please subscribe to Asymptote at
http://freshmeat.net/projects/asy
If you find a bug in Asymptote, please check (if possible) whether the bug is still present
in the latest Subversion developmental code (see Section 2.8 [Subversion], page 8) before
submitting a bug report. New bugs can be submitted using the Bug Tracking System at
http://sourceforge.net/projects/asymptote
To see if the bug has already been fixed, check bugs with Status Closed and recent lines in
http://asymptote.sourceforge.net/ChangeLog
Asymptote can be configured with the optional GNU library libsigsegv, available from
http://libsigsegv.sourceforge.net, which allows one to distinguish user-generated
Asymptote stack overflows (see [stack overflow], page 63) from true segmentation faults
(due to internal C++ programming errors; please submit the Asymptote code that generates
such segmentation faults along with your bug report).
Chapter 13: Debugger 162
13 Debugger
Asymptote now includes a line-based (as opposed to code-based) debugger that can assist
the user in following flow control. To set a break point in file file at line line, use the
command
void stop(string file, int line, code s=quote{});
The optional argument s may be used to conditionally set the variable ignore in plain_
debugger.asy to true. For example, the first 10 instances of this breakpoint will be ignored
(the variable int count=0 is defined in plain_debugger.asy):
stop("test",2,quote{ignore=(++count <= 10);});
To set a break point in file file at the first line containing the string text, use
void stop(string file, string text, code s=quote{});
To list all breakpoints, use:
void breakpoints();
To clear a breakpoint, use:
void clear(string file, int line);
To clear all breakpoints, use:
void clear();
The following commands may be entered at the debugging prompt:
h help;
c continue execution;
i step to the next instruction;
s step to the next executable line;
n step to the next executable line in the current file;
f step to the next file;
r return to the file associated with the most recent breakpoint;
t toggle tracing (-vvvvv) mode;
q quit debugging and end execution;
x exit the debugger and run to completion.
Arbitrary Asymptote code may also be entered at the debugging prompt; however, since
the debugger is implemented with eval, currently only top-level (global) variables can be
displayed or modified.
The debugging prompt may be entered manually with the call
void breakpoint(code s=quote{});
Chapter 14: Acknowledgments 163
14 Acknowledgments
Financial support for the development of Asymptote was generously provided by the
Natural Sciences and Engineering Research Council of Canada, the Pacific Institute for
Mathematical Sciences, and the University of Alberta Faculty of Science.
We also would like to acknowledge the previous work of John D. Hobby, author of the
program MetaPost that inspired the development of Asymptote, and Donald E. Knuth,
author of TEX and MetaFont (on which MetaPost is based).
The authors of Asymptote are Andy Hammerlindl, John Bowman, and Tom Prince.
Sean Healy designed the Asymptote logo. Other contributors include Radoslav Marinov,
Orest Shardt, Chris Savage, Philippe Ivaldi, Olivier Guibé, Jacques Pienaar, Mark Henning,
Steve Melenchuk, Martin Wiebusch, and Stefan Knorr.
Index 164
Index
! <
! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 < . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
!= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55, 59 <= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
% =
== . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55, 59
% . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
%= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
>
& > . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
>= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
& . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12, 59
&& . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
?
? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
*
* . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36, 58
** . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 ^
*= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 ^ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
^= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
^^ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
+
+ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36, 58
++ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
|
+= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 | . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
|| . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
- 2
- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
2D graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
-- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11, 59
--- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
-= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 3
-c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
-l . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156 3D graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
-u . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 3D grids. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
-V . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4, 9 3D rendering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
. A
.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 a4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
.asy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 abort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
abs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24, 66
accel. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31, 134
access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
/ acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
/ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 acos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
/= . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 aCos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
acosh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
add . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
: Ai . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Ai_deriv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
:: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Airy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Index 165
alias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 B
align . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 babel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Align . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 background color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
all . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 BackView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Allow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 Bar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
and . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 Bar3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
AND . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59 Bars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
angle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 Bars3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
animate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5, 53, 91 barsize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
animation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 base modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
annotate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 basealign . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
antialias . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129, 155 baseline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
antialiasing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 batch mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
append . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 beep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
append . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 BeginArcArrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
arc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29, 130 BeginArcArrow3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Arc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 BeginArrow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
ArcArrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 BeginArrow3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
ArcArrow3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 BeginBar . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
ArcArrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 BeginBar3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
ArcArrows3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 BeginDotMargin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
arclength . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31, 134 BeginDotMargin3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
arctime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31, 134 BeginMargin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 BeginMargin3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
arithmetic operators . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 BeginPenMargin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68 BeginPenMargin2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
array iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 BeginPenMargin3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67 BeginPoint. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
arrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15, 20 Bessel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Arrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 bevel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
arrow keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 beveljoin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Arrow3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 bezulate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Arrows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 Bi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Arrows3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 Bi_deriv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
as . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 binary format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
asin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 binary operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
aSin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 binarytree. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
asinh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 binput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Aspect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 Blank . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 block.bottom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
asy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 block.bottomleft. . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
asy-mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 block.bottomright . . . . . . . . . . . . . . . . . . . . . . . . . . 144
asy.vim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 block.center . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
asymptote.sty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 block.draw . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
asymptote.xml . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 block.left . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
ASYMPTOTE_CONFIG. . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 block.position . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
atan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 block.right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
aTan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 block.top . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
atan2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 block.topleft . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
atanh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 block.topright . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
atleast . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 bool . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
attach . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81, 101 bool3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
autoadjust . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 boolean operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
autoimport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 Bottom . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
automatic scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 BottomTop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
axialshade. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 BottomView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
axis . . . . . . . . . . . . . . . . . . . . . . . . . . . 115, 117, 138, 139 bounding box. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
azimuth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
Index 166
boutput . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 constructors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
box . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45, 47, 131 context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
bp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 continue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23, 162
break . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 contour . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
breakpoints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 contour3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
brick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 controls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12, 126
broken axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112 controlSpecifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
bug reports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161 convert . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5, 53, 90, 155
buildcycle. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 convertOptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Button-1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 Coons shading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Button-2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159 copy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
BWRainbow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 cos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
BWRainbow2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 Cos . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
cosh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
cputime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
C crop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
C string. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 cropping graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
CAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 cross. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26, 103
calculateTransform . . . . . . . . . . . . . . . . . . . . . . . . . . 47 crossframe. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74 crosshatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
cbrt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 csv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72, 73
cd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 cubicroots. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
ceil . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 curl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12, 126
center . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 curlSpecifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Center . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 currentpen. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
checker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41 currentprojection . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Chinese . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
choose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 custom axis types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Ci . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 custom mark routine . . . . . . . . . . . . . . . . . . . . . . . . . 105
circle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29, 130, 144 custom tick locations . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Circle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 cut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
circlebarframe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 cycle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9, 11, 126
CJK. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 cyclic . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30, 35, 67, 134
clear. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52, 162 cyclicflag. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
clip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Cyrillic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
cm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
cmd . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
cmyk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 D
colatitude. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 dashdotted. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
color . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 dashed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
coloredNodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
coloredpath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 date . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
coloredSegments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143 Debian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
colorless . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 debugger . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
colors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 declaration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
comma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 deconstruct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
comma-separated-value mode . . . . . . . . . . . . . . . . . . 72 default arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
command-line options . . . . . . . . . . . . . . . . . . . . . . 5, 153 defaultformat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
comment character . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 DefaultHead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
compass directions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10 DefaultHead3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Compiling from UNIX source . . . . . . . . . . . . . . . . . . . 6 defaultpen . . . . . . . . . . . . . . . . . . . . . 37, 39, 40, 43, 44
complement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 deferred drawing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
concat . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 degrees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24, 65
conditional. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23, 59 Degrees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
config . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154 delete. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53, 67
configuration file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
configuring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 diagonal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
conj . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 diamond . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Index 167
functionshade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 I
I . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
i_scaled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
G iconic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
gamma . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 identity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44, 65, 71
Gaussrand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 if . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
geometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 IgnoreAspect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
getc . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 image . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
getpair . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 ImageMagick . . . . . . . . . . . . . . . . . . . . . . . . . . . 5, 90, 155
getreal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 implicit casts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
getstring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 implicit linear solver. . . . . . . . . . . . . . . . . . . . . . . 92
gettriple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 implicit scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
glOptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129, 155 import . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
GNU Scientific Library . . . . . . . . . . . . . . . . . . . . . . . . . 66 inches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
gouraudshade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 including images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Gradient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 inheritance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
gradient shading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 initialized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 initializers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
graph3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137 InOutTicks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
graphic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51, 157
graphical user interface . . . . . . . . . . . . . . . . . . . . . . . 159 insert. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27, 67
gray . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 inside . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
grayscale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 inst . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
Grayscale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
grid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41, 110 int . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
grid3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 integer division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
gs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 interactive mode. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
gsl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 interior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
international characters . . . . . . . . . . . . . . . . . . . . . . . . 92
GSL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
interp . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
gsOptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
interpolate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
GUI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
intersect . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32, 86, 134
GUI installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
intersectionpoint . . . . . . . . . . . . . . . . . . . 33, 86, 134
GUI usage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
intersectionpoints . . . . . . . . . . . . . . . . . . . . . . 33, 134
guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
intersections . . . . . . . . . . . . . . . . . . . . . . . . . . . 32, 134
guide3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
InTicks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
intMax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
intMin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
H inverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44, 71
hatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 invert . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
height . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 invisible . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 J
Hermite . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 J . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65, 66
Hermite(splinetype splinetype . . . . . . . . . . . . . . 94 Japanese . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
hex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
hexidecimal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27, 37
hidden surface removal . . . . . . . . . . . . . . . . . . . . . . . 135 K
histogram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 K . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 k_scaled . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
historylines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157 Kate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
HookHead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 KDE editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
HookHead3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 keyboard bindings: . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
Horizontal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145 keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
hypot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 keywords . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Korean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Index 169
L Margin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 Margin3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 margins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 Margins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
labelpath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 Margins3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
labelpath3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93 mark . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
labelx . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 markangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
labely . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99 marker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Landscape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46 markers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
lastcut . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 marknodes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
lasy-mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 markuniform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
latex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155 math . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
LaTeX fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 mathematical functions . . . . . . . . . . . . . . . . . . . . . . . . 65
LaTeX usage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81 max . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33, 45, 70, 134
latin1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92 maxbound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25, 26
latitude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 maxtile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
latticeshade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 maxtimes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
layer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 maxviewport . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
leastsquares. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87, 116 merge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Left . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 MetaPost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
LeftRight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 MetaPost ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
LeftSide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 MetaPost cutafter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
LeftTicks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96, 97 MetaPost cutbefore . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
LeftView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 MetaPost pickup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 MetaPost whatever . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
legend . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16, 101 Microsoft Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Legendre . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 MidArcArrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
length . . . . . . . . . . . . . . . . . 24, 25, 27, 30, 35, 67, 134 MidArcArrow3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
letter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 MidArrow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
libm routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 MidArrow3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
libsigsegv . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63, 161 midpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107 MidPoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72, 73 min . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33, 45, 70, 134
line mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 minbound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25, 26
Linear . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 minipage . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
linecap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 mintimes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
linejoin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 miterjoin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
lineskip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 miterlimit. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
linewidth . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 mm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
locale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 mouse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
Log . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 mouse bindings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
log-log graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 Move . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
log10 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 MoveQuiet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
log1p . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 multisample . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
log2 graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111 multisampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
logarithmic graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
logical operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
longdashdotted . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 N
longdashed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38 N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
longitude . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 named arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
new . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54, 68
newframe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
M newl . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
MacOS X binary distributions . . . . . . . . . . . . . . . . . . . . 3 newton . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
makepen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 next . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 NFSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Index 170
quotient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58 S
S . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
safe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
R save . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
radialshade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 saveline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
RadialShade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44, 109, 133
radians . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Scale. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20, 109
radius . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31, 134 scale3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
Rainbow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122 scaled graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
rand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 scientific graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
randMax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 scroll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
read1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
read2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 search paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
read3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73 Seascape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 secondary axis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
reading string arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . 72 secondaryX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
readline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 secondaryY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
real . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 seconds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
realDigits. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 seek . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
realEpsilon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 seekeof . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
realMax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 segmentation fault . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
realMin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 self operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
realmult . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
rectangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4, 154
recursion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63 sgn . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
reflect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45 shading. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Relative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44, 45, 133
relpoint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 Shift . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
reltime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 shiftless . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
remainder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 shipout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
rename . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 showtarget . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
render . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128, 155 Si . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
replace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 signed. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52, 73
resetdefaultpen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44 SimpleHead. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
rest arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64 simplex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
restore . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 simpson . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
restricted. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 sin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 Sin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
reverse . . . . . . . . . . . . . . . . . . . . . . . 27, 32, 35, 69, 134 single. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52, 73
rewind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 singleint . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
rfind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 singlereal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
rgb . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37 sinh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Riemann zeta function . . . . . . . . . . . . . . . . . . . . . . . . . 66 size . . . . . . . . . . . . . . . . . . . . . . 30, 35, 45, 46, 134, 155
Right . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98 size3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
RightSide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 slant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
RightTicks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96, 97 Slant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
RightView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132 sleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Rotate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 slice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Rotate(pair z) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 slices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
round . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 slide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
roundcap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 slopefield . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
roundedpath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90 solid . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
roundjoin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 solids . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142
roundrectangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144 solve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
sort . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69, 70
RPM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Spline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94, 139
runtime imports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
split . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Russian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
sqrt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
Index 172
squarecap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 this . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
srand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 three . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
stack overflow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63, 161 tick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
static . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 ticks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
stats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 Ticks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96, 97
stdin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 tildeframe. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
stdout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 tile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 tilings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
stickframe. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87 time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
stop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162 times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
straight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30, 134 Top . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Straight . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 TopView . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
strftime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 trace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162
string. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26, 27 trailingzero . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
stroke. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17, 19 transform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44, 133
strokepath. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 transform3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133
strptime . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28 transparency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
struct . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 transpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
subpath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32, 134 trembling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
subpictures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 triangle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
substr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 triangulate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
Subversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 tridiagonal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
sum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70 trigonometric integrals . . . . . . . . . . . . . . . . . . . . . . . . . 66
superpath . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 triple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Suppress . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 TrueMargin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
SuppressQuiet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 TrueMargin3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135
surface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127, 128, 139 tube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128, 143
SVN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 tutorial . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
system . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53, 155 typedef . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29, 62
syzygy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
U
T undefined . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
tab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 unfill . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
tab completion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 UnFill. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15, 47
tan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 unicode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Tan . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66 uniform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
tanh . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 Uninstall . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
target . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131 unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24, 25
tell . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52 unitbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13, 131
tension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12, 126 unitcircle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11, 130
tensionSpecifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 unitrand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
tensor product shading . . . . . . . . . . . . . . . . . . . . . . . . 18 unitsize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10, 46
tensorshade . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18 UNIX binary distributions . . . . . . . . . . . . . . . . . . . . . . 3
tex . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50, 155 unpacking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
TeX fonts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40 unravel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
TEX string . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26 up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
texcommand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5 update . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
TeXHead . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 UpsideDown . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46, 47
TeXHead3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 usepackage. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
texpath. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5, 21 user coordinates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
texpreamble . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50 user-defined operators . . . . . . . . . . . . . . . . . . . . . . . . . 60
texreset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 usleep . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
textbook graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
tgz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
thick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 V
thin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128 variable initializers . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Index 173