// Introduction to Asymptote orientation=Landscape; settings.tex="pdflatex"; import slide; import three; import animate; usersetting(); viewportsize=pagewidth-2pagemargin; // To generate bibliographic references: // asy -k goysr // bibtex goysr_ bibliographystyle("alpha"); itempen=fontsize(22pt); titlepage("Asymptote: The Vector Graphics Language", "Andy Hammerlindl and John Bowman", "University of Toronto and University of Alberta","August 16, 2007", "http://asymptote.sf.net"); title("History"); item("\TeX\ and METAFONT (Knuth, 1979)"); item("MetaPost (Hobby, 1989): 2D Bezier Control Point Selection"); item("Asymptote (Hammerlindl, Bowman, Prince, 2004): 2D \& 3D Graphics"); title("Statistics (as of April, 2007)"); item("Runs on Windows, Mac OS X, Linux, etc."); item("1800 downloads a month from {\tt asymptote.sourceforge.net}."); item("33\ 000 lines of C++ code."); item("18\ 000 lines of Asymptote code."); title("Vector Graphics"); item("Raster graphics assign colors to a grid of pixels."); figure("pixel.pdf"); item("Vector graphics are graphics which still maintain their look when inspected at arbitrarily small scales."); asyfigure(asywrite(" picture pic; path zoombox(real h) { return box((-h,-h/2),(min(10,h),min(10,h)/2)); } frame zoom(real h, real next=0) { frame f; draw(f, (0,-100){W}..{E}(0,0), Arrow); clip(f, zoombox(h)); if(next > 0) draw(f, zoombox(next)); return scale(100/h)*f; } add(zoom(100), (0,0)); add(zoom(10), (200,0)); add(zoom(1), (400,0)); ")); title("Cartesian Coordinates"); asyfilecode("diagonal"); item("units are {\tt PostScript} {\it big points\/} (1 {\tt bp} = 1/72 {\tt inch})"); item("{\tt --} means join the points with a linear segment to create a {\it path}"); item("cyclic path:"); asyfilecode("square"); title("Scaling to a Given Size"); item("{\tt PostScript} units are often inconvenient."); item("Instead, scale user coordinates to a specified final size:"); code(" size(101,101); draw((0,0)--(1,0)--(1,1)--(0,1)--cycle); "); asyfigure("square"); item("One can also specify the size in {\tt cm}:"); asycode(" size(3cm,3cm); draw(unitsquare); "); title("Labels"); item("Adding and aligning \LaTeX\ labels is easy:"); asyfilecode("labelsquare","height=6cm"); title("2D Bezier Splines"); item("Using {\tt ..} instead of {\tt --} specifies a {\it Bezier cubic spline}:"); code(" draw(z0 .. controls c0 and c1 .. z1,blue); "); asyfigure("beziercurve","height=7cm"); equation("(1-t)^3 z_0+3t(1-t)^2 c_0+3t^2(1-t) c_1+t^3 z_1, \qquad t\in [0,1]."); title("Smooth Paths"); item("Asymptote can choose control points for you, using the algorithms of Hobby and Knuth \cite{Hobby86,Knuth86b}:"); string bean=" pair[] z={(0,0), (0,1), (2,1), (2,0), (1,0)}; "; asycode(preamble="size(130,0);",bean+" draw(z[0]..z[1]..z[2]..z[3]..z[4]..cycle, grey+linewidth(5)); dot(z,linewidth(7)); "); item("First, linear equations involving the curvature are solved to find the direction through each knot. Then, control points along those directions are chosen:"); asyfigure(asywrite(preamble="size(130,0);",bean+" path p=z[0]..z[1]..z[2]..z[3]..z[4]..cycle; dot(z); draw(p,lightgrey+linewidth(5)); dot(z); picture output; save(); for (int i=0; i0$ and a shift $b$ so that all of the coordinates when transformed will lie in the interval $[0,S]$. That is, if $u$ and $t$ are the user and truesize components:"); equation("0\le au+t+b \le S."); item("We are maximizing the variable $a$ subject to a number of inequalities. This is a linear programming problem that can be solved by the simplex method."); title("Sizing"); item("Every addition of a coordinate $(t,u)$ adds two restrictions"); equation("au+t+b\ge 0,"); equation("au+t+b\le S,"); remark("and each drawing component adds two coordinates."); item("A figure could easily produce thousands of restrictions, making the simplex method impractical."); item("Most of these restrictions are redundant, however. For instance, with concentric circles, only the largest circle needs to be accounted for."); asyfigure(asywrite(" import palette; size(160,0); pen[] p=Rainbow(NColors=11); for (int i=1; i<10; ++i) { draw(scale(i)*unitcircle, p[i]+linewidth(2)); } ")); title("Redundant Restrictions"); item("In general, if $u\le u'$ and $t\le t'$ then"); equation("au+t+b\le au'+t'+b"); remark("for all choices of $a>0$ and $b$, so"); equation("0\le au+t+b\le au'+t'+b\le S."); item("This defines a partial ordering on coordinates. When sizing a picture, the program first computes which coordinates are maximal (or minimal) and only sends effective constraints to the simplex algorithm."); item("In practice, the linear programming problem will have less than a dozen restraints."); item("All picture sizing is implemented in Asymptote code."); title("Infinite Lines"); item("Deferred drawing allows us to draw infinite lines."); code("drawline(P, Q);"); asyfigure("elliptic","height=12cm"); title("A Final Example: Quilting"); asyfigure(asywrite(" import math; int n=8, skip=3; pair r(int k) { return unityroot(n,k); } pen col=blue, col2=purple; guide square=box((1,1),(-1,-1)); guide step(int mult) { guide g; for (int k=0; k