[Tex/LaTex] Showcase of translations to Asymptote from TikZ/PSTricks

asymptotepstrickstikz-pgf

So you already know TikZ and/or PSTricks, but you would like to expand your knowledge by learning Asymptote as well? Here's your chance.

The task/question: Find an example of an impressive diagram drawn with TikZ or PSTricks (ideally but not necessarily one you created yourself), and redraw it using Asymptote. Your redrawn version should be at least as good as the original, except that 3d Asymptote pictures are allowed to be high-resolution rasterized images even if the original was a vector drawing. You should include, at a minimum, a link to the original; ideally, you should include (if allowed by copyright) the source code for the original and a picture of it. My hope is that ultimately, the answers to this question will become a useful resource for TikZ and PSTricks users seeking to learn Asymptote.

To sweeten the deal, I will be awarding a bounty of 500 reputation points to the most impressive answer. "Most impressive" will be determined by votes at the time the bounty ends, although I reserve the right to disqualify answers that I believe violate the letter or the spirit of original question.

Additional, semi-selfish motive: Please let me know if you find my Asymptote tutorial useful. Other potentially useful resources include the official documentation and this tutorial in French for 3d stuff.


If you would like to answer this question but would like more specific examples, try translating answers from this question on drawing an egg or this question on drawing a Christmas tree.

Best Answer

For a baseline, here's an example I did when I was first learning Asymptote. The original TikZ picture (taken from Lecture 2 of these class notes) is on the left; the Asymptote translation is on the right.

enter image description here

The code is below. Note that the translation is a bit more thorough than necessary--for instance, I don't expect most answers to worry about changing the default line width from 0.5pt to 0.4pt. It's also less thorough than it conceivably could be: the arrow tips are not identical, nor are the heights of the labels.

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usepackage[squaren]{SIunits}
\usepackage[inline]{asymptote}

\begin{document}
\begin{asydef}
    defaultpen(fontsize(10pt));
\end{asydef}
\begin{tikzpicture}[scale=4.0, axes/.style={thick,->}]
    \draw[axes] (-1.2,0) -- (1.2,0) node[right] {$x$};
    \draw[axes] (0,-1.2) -- (0,1.2) node[above] {$y$};

    \draw (0,0) circle[radius=1];

    \draw[->] (0.2,0) node[above right]{$\scriptstyle t~\rad$} arc[start angle=0, end angle=30, radius=0.2];
    \draw[->] (1.07,0) arc[start angle=0, end angle=30, radius=1.07] node[right]{$t$};
    \draw (0,0) -- node[below]{$\Delta x = \cos t$} ({sqrt(3)/2},0) 
        -- node[right,fill=white]{$\Delta y = \sin t$} ({sqrt(3)/2},0.5) 
        -- cycle;
    \path (0,0) -- node[above]{$1$} ({sqrt(3)/2},0.5);
\end{tikzpicture}

\begin{asy}
    unitsize(4cm);
    pen tikzthick = linewidth(0.8pt);
    defaultpen(linewidth(0.4pt));       // This sets the default pen width to 0.4pt to match TikZ; in Asymptote, the default width is 0.5pt.

    draw((-1.2,0)--(1.2,0), arrow=Arrow(TeXHead), L=Label("$x$",EndPoint), p=tikzthick);
    draw((0,-1.2)--(0,1.2), arrow=Arrow(TeXHead), L=Label("$y$",EndPoint), p=tikzthick);

    draw(circle(c=(0,0), r=1));

    draw(arc(c=(0,0), r=0.2, angle1=0, angle2=30),
        arrow=Arrow(TeXHead), 
        L=Label("$\scriptstyle t~\rad$",position=BeginPoint,align=NE) );
    draw(arc(c=(0,0), r=1.07, angle1=0, angle2=30),
        arrow=Arrow(arrowhead=TeXHead),
        L=Label("$t$",position=EndPoint,align=E) );
    path triangle = (0,0)--(sqrt(3)/2,0)--(sqrt(3)/2,1/2)--cycle;
    draw(triangle);
    label(subpath(triangle,0,1), L="$\Delta x = \cos t$", align=S);
    label(subpath(triangle,1,2), L="$\Delta y = \sin t$", align=E, filltype=Fill(white));
    label(subpath(triangle,2,3), L="$1$", align=N);
\end{asy}
\end{document}