Professional Documents
Culture Documents
Graphics: GL PRC PDF: An Interactive 3 of A B Ezier Surface Representation of The Utah Teapot
Graphics: GL PRC PDF: An Interactive 3 of A B Ezier Surface Representation of The Utah Teapot
Graphics
Asymptote: Lifting TEX to three dimensions
John C. Bowman and Orest Shardt
Abstract
Asymptote, a modern successor to the METAPOST
vector graphics language that features robust floating-
point numerics, high-order functions, and deferred
drawing, has recently been enhanced to generate
fully interactive three-dimensional output. This
data can either be viewed with Asymptote’s native
OpenGL-based renderer or internally converted to Figure 1: An interactive 3D PDF of a Bézier surface
Adobe’s highly compressed PRC format for embed- representation of the Utah Teapot.
ding within a PDF file. Asymptote thus provides
the scientific community with a self-contained and
powerful TEX-aware facility for generating portable within a PDF file, as illustrated in Fig. 1.2 In contrast,
interactive three-dimensional PDF files. the version of U3D supported by Adobe can only
render surfaces described by polygons and hence is
not a suitable vector graphics format.
1 Introduction
The descriptive vector graphics language Asymptote1 3 Three-dimensional TEX
was developed to provide a standard for drawing TEX produces output in a special device independent
mathematical figures, just as TEX and LATEX have format (DVI). While this output can be easily turned
become the standard for typesetting equations in the into PostScript, one needs a way of extracting Bézier
mathematics, physics, and computer science commu- curves that describe properly kerned font characters.
nities [1]. For professional quality and portability, Asymptote does this by overloading the PostScript
Asymptote natively generates PostScript, PDF, and /show operator, as described in Appendix A. Special
PRC vector graphics output. The latter is a highly care was required to handle the filled rectangles that
compressed 3D format that is typically embedded TEX uses to draw square root symbols and fraction
within a PDF file and viewed with Adobe Reader. bars. The resulting exact 2D vector representation
In both two and three dimensions, consistent of the original TEX input is treated by Asymptote
fonts and equations should be used in the graphics as an array of paths to be filled with the PostScript
and text portions of a document. This implies that nonzero winding number fill rule.
labels must be typeset directly by TEX. This article The routine bezulate described in Figs. 2 and 3,
provides an overview of the major advances in the along with the nondegenerate patch splitting algo-
current version (1.82) of Asymptote that allow it to rithms described in [3], is used to convert the result-
extract and lift Bézier font descriptions generated by ing Bézier paths to Bézier surfaces. These surfaces
TEX and Dvips into 3D, using efficient algorithms are then output in the PRC format, along with a
for partitioning planar regions into nondegenerate rendered preview image for noninteractive viewing
Coons patches [3]. Together with 3D generalizations and printing. Using these techniques, Asymptote is
of the METAFONT path operators and a method for then able to typeset the Gaussian integral in Fig. 4
computing twist-free tubes and arrowheads, these as an interactive 3D diagram.
algorithms provide the 3D foundation of Asymptote.
4 Thick lines in 3D
2 Bézier surfaces Figure 5 depicts capped thick lines and Asymptote’s
A major recent advance in Asymptote is the ability five (METAPOST-inspired) path connectors [2]:
to embed Bézier surfaces as interactive PRC content -- .. & --- ::
for the following path, when lifted to the x–y plane:
1Andy Hammerlindl, John Bowman, and Tom Prince,
available under the GNU Lesser General Public License from 2 An interactive PDF version of this article may be found
http://asymptote.sourceforge.net/. at http://asymptote.sourceforge.net/articles/.
A
B
C
5 Arrowheads in 3D
Figure 4: The Gaussian integral lifted to 3D. Arrows are frequently used in illustrations to draw
attention to important features. We designed curved
6 Double deferred drawing code shows how to draw circles with 5mm radii at
Journal size constraints typically dictate the final each vertex of a unit cube, independent of the overall
width and height, in PostScript coordinates, of a 2D picture scaling (cf. Fig. 12):
or projected 3D figure. However, it is often conve- import three;
nient for users to work in more physically meaningful size(4cm);
coordinates. This requires deferred drawing: a graph- currentprojection=orthographic(5,4,2);
ical object cannot be drawn until the actual scaling
of the user coordinates (in terms of PostScript coor- void Circle(triple c, pen p) {
dinates) is known [1]. One queues a function to do picture pic;
the drawing only once the overall scaling is known. draw(pic,scale3(5mm)*unitcircle3,p);
Asymptote’s high-order functions provide a flexible add(pic,c);
}
automatic sizing mechanism: either or both of the
3D model dimensions and the final projected 2D size path3[] g=unitbox;
may be specified. This requires two levels of deferred draw(g);
drawing, a first pass to size the 3D model and a
second pass to scale the resulting picture to fit the for(path3 p : g)
2D size specification. for(int i=0; i < length(p); ++i)
Deferred drawing allows one to draw a fixed- Circle(point(p,i),red);
sized object at a scaled coordinate. The following