# Nice scientific pictures show off

Show off your best scientific illustration !

The main purpose of this question is to share beautiful scientific pictures, preferably with an educational aspect.

## Content

Your post must contain a nice picture and the associated code. One can post several pictures, but it must be done in different replies. Of course, it must be done with LaTeX & Friends : the post must start with a short sentence to present the language that you chose (TikZ, Asymptote ...) and the main packages that helped you to make the picture. Don't hesitate to add comments.

## Reward

The satisfaction to share without expecting a reward :)

Ok ... 300 points reputation bounty for the best up-voted post until the 15th of Feb.

I'll contact Texample.net webmaster to see if he is interested to share the best illustrations, with the participant's agreement of course.

Contest: Show Off Your Skillz in TeX & Friends

-
that's easy :p dx.doi.org/10.1007/978-3-642-36763-2_46 –  percusse Feb 5 at 8:43
I'll be glad if Till Tantau himself decide to participate, but that would be a bit unfair ... :) –  Thomas Feb 5 at 8:47
What a wonderful question and answers, this is a true feeding frenzy for my inner geek :) –  Kuba Ober Feb 6 at 15:28
I'm surprised this question wasn't closed already by people like this, on the grounds that it's not a question. Or does that apply only to SO, not to tex.SE? –  Dan Dascalescu Feb 7 at 0:06
@DanDascalescu: Here on TeX.SX the mood is much more laazyyy. Think alone the existence of a tag big-list (click on it). –  Speravir Feb 7 at 0:22
show 17 more comments

Mandelbrot Set

Well, I didn't really come up with this, especially the coloring function. I pieced the code together from different tutorials some time ago, and now simply translatet it to Asymptote.

real iterate(pair z, pair c, int N) {
pair zsquare = 0;

int n = 0;

do {
zsquare = (z.x * z.x, z.y * z.y);
z = (zsquare.x + zsquare.y * -1, 2 * z.x * z.y) + c;
++n;
}
while (zsquare.x + zsquare.y < 4 && n < N);

zsquare = (z.x * z.x, z.y * z.y);
return n - log(.5 * log(zsquare.x + zsquare.y) / log(N)) / log(2);

return n;
}

void mandelbrot(pair size, real zoom, pair pos, int N) {
for(int x = 0; x < size.x; ++x) {
for(int y = 0; y < size.y; ++y) {
pair z = (x / size.x, y / size.y) * zoom - pos;

real res = iterate(z, z, N) / N;

fill(box((x, y), (x + 2, y + 2)), rgb(sin(res * 4), sin(res * 5), sin(res * 6)));
}
}
}

mandelbrot((300, 300), 3, (2, 1.5), 128);

-

I couldn't bear to let this go without at least one example of a picture produced by mfpic. It is not very flashy, but it illustrates that mfpic has built-in commands to produce figures in the hyperbolic geometry of a disk (for those of us who study function theory in the unit disk.):

\documentclass{article}
\usepackage[metapost,mplabels]{mfpic}
\opengraphsfile{mypics}
\begin{document}
Hyperbolic metric disks:

\begin{mfpic}[72]{-1}{1}{-1}{1}
\setmfpair{Z}{(dir 45)/3}
\setmfpair{W}{Moebius (Z)(.5*dir -45)}
\draw\gfill[gray(.94)]\circle{(0,0),1}
\draw\gfill[gray(.87)]\pshcircle{Z,4/5}
\gfill[gray(.80)]\pshcircle{Z,1/2}
\draw\gfill[gray(.73)]\pshcircle{W,1/2}
\draw\pshcircle{Z,1/2}
\tlpointsep{3bp}
\point{Z,W,(0,0)}
\tlabel[br]{Z}{$z$}
\tlabel[tl]{W}{$w$}
\tlabel[tr]{(0,0)}{$0$}
\end{mfpic}

Hyperbolic geodesics:

\begin{mfpic}[72]{-1}{1}{-1}{1}
\circle{(0,0),1}
\draw\gfill[gray(.88)]
\lclosed
\connect
\hypergeodesic{.999*dir 0, .999*dir 120}
\hypergeodesic{.999*dir 120, .999*dir 240}
\hypergeodesic{.999*dir 240, .999*dir 0}
\endconnect
\mfpfor{K=6,12,24,48}
\mfpfor{J=0 upto K-1}
\rotatepath{(0,0),J*(360/K)}\hypergeodesic{.999*dir 0, .999*dir (360/K)}
\endmfpfor
\endmfpfor
\end{mfpic}

\closegraphsfile
\end{document}


-
show 4 more comments

Edit: Oops, realized too late this was about images drawn using latex.

Typing up a conference paper for ICGG 2014 in Innsbruck about phase spaces and fitness landscapes. Although I'm a programmer for a 3D CAD company, I've grown very tired of rendered images as of late. I find it very difficult to draw focus to specific salient details in a digital image.

Although I heavily rely on 3D software and custom programming to generate the geometry in these images, everything is ultimately hand-drawn. Labels are added directly in LaTeX using \put commands, so the images are kept clean.

Not sure what anyone is going to learn from the code, but here is the tex for the bottommost image:

\begin{figure}[H] \centering
\begin{overpic}[width=.95\linewidth]{Images/OverconstrainedLandscape}
\put (40,15) {\smaller[2] $\nicecirc{1}$}
\put (66,35) {\smaller[2] $\nicecirc{1}$}
\put (3,46)  {\smaller[2] $\nicecirc{2}$}
\put (45,55) {$\pazocal{L}^\prime$}
\end{overpic}
\caption{Geometry of overconstrainedness}
\label{fig:overconstrainedlandscape}
\end{figure}

-
This does not really answer the question, because the question is interested in graphics that were actually created in LaTeX, and not included from image files. Also please post an image of the result of the included code. –  marczellm Feb 11 at 21:49
Very nice pictures. It would be great if we could draw such pictures in LaTeX:-) –  Marc van Dongen Feb 14 at 12:26
show 4 more comments

Prime factorization

\documentclass{article}

\usepackage{pst-tree}
\usepackage{xintexpr}
\usepackage{siunitx}

\psset{
levelsep=1,
treesep=1,
nodesep=2pt
}

\catcode\_ 11

% This code (non-expandable) produces {{}{}{N}} followed by
% successive braced triplets {{p}{k}{m}} where p is
% a prime factor of N,  k its exponent in N, and m is
% the result of dividing N by p^k and all previous
% powers of smaller primes. So, the last triplet has m = 1.

% The code uses package xint to be able to deal
% with numbers larger than the TeX limit of 2^{31}-1
% on count registers.

\def\factorize#1{%
\edef\factorize_N{#1}%
\def\factorize_exp{0}%
\edef\factors{{{}{}{\factorize_N}}}%
\factorize_i
}

\def\factorize_i{%
\if\xintOdd{\factorize_N}1%
\expandafter \factorize_ii
\else
\edef\factorize_exp{\xintInc{\factorize_exp}}%
\edef\factorize_N{\xintHalf{\factorize_N}}%
\expandafter \factorize_i
\fi
}

\def\factorize_ii{%
\if\xintSgn{\factorize_exp}1%
\edef\factors{\factors{{2}{\factorize_exp}{\factorize_N}}}%
\fi
\if\expandafter\XINT_isOne\expandafter{\factorize_N}1%
\else
\def\factorize_M{3}%
\def\factorize_exp{0}%
\expandafter \factorize_iii
\fi
}

\def\factorize_iii{%
\xintAssign\xintDivision\factorize_N\factorize_M\to
\factorize_Q\factorize_R
\xintSgnFork{\xintSgn\factorize_R}%
{}%
{\edef\factorize_exp{\xintInc{\factorize_exp}}%
\let\factorize_N\factorize_Q
\factorize_iii}%
{\factorize_iv}%
}

\def\factorize_iv{%
\if\xintSgn{\factorize_exp}1%
\edef\factors{\factors{{\factorize_M}{\factorize_exp}{\factorize_N}}}%
\fi
\if\expandafter\XINT_isOne\expandafter{\factorize_N}1%
\else
% Here N > 1, N = QM+R (0 < R < M) is < M(Q+1) and N has no
% prime factors at most equal to M. If a prime P > M divides N, the
% quotient N/P will be < Q+1, hence at most Q. If Q <= M, then
% N/P must be 1 else there would be some prime <=M dividing N.
\if\xintGeq\factorize_M\factorize_Q 1% Implies that N is prime.
\edef\factors{\factors{{\factorize_N}{1}{1}}}% We stop here.
\else% We go on testing with bigger factors.
% \edef\factorize_M{\xintInc{\xintInc{\factorize_M}}}%
\def\factorize_exp{0}%
\expandafter \expandafter \expandafter \factorize_iii
\fi
\fi
}

\catcode\_ 8

% We now define the macro \FactorTree which will produce
% a tree displaying the factorization.

\newtoks\FactorTreeA
\newtoks\FactorTreeB

\makeatletter

\newcommand*\FactorsToTree[1]{%
\FactorsToTree@ #1%
}

% Macro which was used to produce the images;
% variant follows which skips the exponents equal to 1.

% \newcommand*\FactorsToTree@[3]{%
%     \xintSgnFork{\xintCmp{#3}{1}}% check to see if end has been reached
%     {}%
%     {\FactorTreeA\expandafter{\the\FactorTreeA
%                               \Tcircle{$\num{#1}^{#2}$}%
%                               \TR{1}%
%                               }}%
%     {\FactorTreeA\expandafter{\the\FactorTreeA
%                              \Tcircle{$\num{#1}^{#2}$}%
%                              \psTree{\TR{\num{#3}}}}%
%      \FactorTreeB\expandafter{\the\FactorTreeB \endpsTree}}%
% }

% This variant will not print the exponents equal to 1:

\newcommand*\FactorsToTree@[3]{%
\ifnum 0#2=1 % First triplet has an empty #2, hence the trick with 0.
\expandafter\@firstoftwo
\else
\expandafter\@secondoftwo
\fi
% Exponent #2 is 1, so don't print it.
{\xintSgnFork{\xintCmp{#3}{1}}% Check to see if end has been reached.
{}%
{\FactorTreeA\expandafter{\the\FactorTreeA
\Tcircle{$\num{#1}$}%
\TR{1}%
}}%
{\FactorTreeA\expandafter{\the\FactorTreeA
\Tcircle{$\num{#1}$}%
\psTree{\TR{\num{#3}}}}%
\FactorTreeB\expandafter{\the\FactorTreeB \endpsTree}}}
% Exponent #2 is > 1 (or absent in the {}{}{N} triplet).
{\xintSgnFork{\xintCmp{#3}{1}}% Check to see if end has been reached.
{}%
{\FactorTreeA\expandafter{\the\FactorTreeA
\Tcircle{$\num{#1}^{#2}$}%
\TR{1}%
}}%
{\FactorTreeA\expandafter{\the\FactorTreeA
\Tcircle{$\num{#1}^{#2}$}%
\psTree{\TR{\num{#3}}}}%
\FactorTreeB\expandafter{\the\FactorTreeB \endpsTree}}}%
}

\makeatletter
\def\@factorinliner #1{\@factorinliner@#1}
\def\@factorinliner@#1#2#3{%
\ifnum #2>1 \expandafter\@firstoftwo\else
\expandafter\@secondoftwo\fi%
{{#1}^{#2}}{\num{#1}}%
}
\newcommand*\FactorizeInline[1]{%
\factorize{#1}%
\xintListWithSep\cdot
{\xintApply\@factorinliner{\expandafter\@gobble\factors}}%
}%

\newcommand*\FactorTree[1]{%
\factorize{#1}%
\FactorTreeA{\@gobbletwo}%
\FactorTreeB{}%
\xintApplyUnbraced\FactorsToTree{\factors}%
\the\FactorTreeA\the\FactorTreeB
\vspace{12ex}
$\num{#1} = \FactorizeInline{#1}$
}

\makeatother

\pagestyle{empty}

\begin{document}

\FactorTree{1689242184972}

\end{document}


-

This diagram shows a decimation process in a database. The first level shows random samples, and subsequent levels calculate the min, mean, and max of groups of four entries from each previous level.

The cool thing about this is that all of the math, including the random number generation, is done directly in TikZ. Since the actual numbers didn't matter, I was able to choose a random seed that made the result look best.

\documentclass[tikz]{standalone}
\usepackage{fullpage}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{etoolbox}

\usetikzlibrary{decorations}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{calc}
\usetikzlibrary{arrows}

\newtoggle{quickdecim}
%\toggletrue{quickdecim} % Uncomment this to render more quickly (non-random)

\begin{document}

\begin{tikzpicture}[,
]
\def\levels{4} % 2, 3, or 4
\pgfmathtruncatemacro{\blocks}{4^(\levels-1)}
\def\maxrand{99}
\def\xoffset{1.1}
\def\yoffset{2.6}
\pgfmathsetseed{31337}
\pgfmathsetmacro{\totalwidth}{10}
\pgfmathsetmacro{\levelheight}{2.4}
\pgfmathsetmacro{\sampleheight}{0.55}

\definecolor{lowcolor} {rgb}{0.6,0.6,1}
\definecolor{highcolor}{rgb}{0.6,1,0.6}

\tikzstyle{Sample} = [
draw, anchor=west,
inner sep=0,
outer sep=0,
minimum height=\sampleheight * 1cm,
font=\small,
text=black,
]

% make random numbers
\pgfmathtruncatemacro{\runningrandarray}{random(\maxrand)}
\foreach \x[count=\xi from 1] in {2,...,\blocks}{
\let\temprand\runningrandarray
\pgfmathtruncatemacro{\tempres}{random(\maxrand)}
\xdef\runningrandarray{\temprand,\tempres}
}
\xdef\randarray{{\runningrandarray}}

% boxes
\foreach \level in {1,...,\levels} {
\coordinate (level\level sample0) at
(\xoffset - \totalwidth / 2,
\yoffset + \levelheight - \levelheight * \level);
\pgfmathsetmacro{\avgblocks}{4^(\level-1)}
\pgfmathsetmacro{\levelblocks}{\blocks / \avgblocks}
\pgfmathsetmacro{\samplewidth}{\totalwidth/\levelblocks}

\foreach \i in {1,...,\levelblocks} {
\iftoggle{quickdecim}{
% can do this instead of using real samples, for speed
\xdef\smin{5}
\xdef\smean{50}
\xdef\smax{95}
}{
% calculate sample values from the randarray
\pgfmathsetmacro{\smin}{100}
\pgfmathsetmacro{\smax}{0}
\pgfmathsetmacro{\samplesum}{0}
\pgfmathsetmacro{\countfrom}{(\i - 1) * \avgblocks}
\pgfmathsetmacro{\countto}{\countfrom + \avgblocks - 1}
\foreach \j in {\countfrom,...,\countto} {
\pgfmathsetmacro{\tmp}{\samplesum + \randarray[\j] / \avgblocks}
\xdef\samplesum{\tmp}
\pgfmathtruncatemacro{\tmp}{min(\smin, \randarray[\j])}
\xdef\smin{\tmp}
\pgfmathtruncatemacro{\tmp}{max(\smax, \randarray[\j])}
\xdef\smax{\tmp}
};
\pgfmathtruncatemacro{\tmp}{\samplesum}
\xdef\smean{\tmp}
}
\pgfmathtruncatemacro{\cmin}{(\smin - 1) / (\maxrand - 1) * 100}
\pgfmathtruncatemacro{\cmean}{(\smean - 1) / (\maxrand - 1) * 100}
\pgfmathtruncatemacro{\cmax}{(\smax - 1) / (\maxrand - 1) * 100}
\pgfmathtruncatemacro{\prev}{\i-1}

\ifnumequal{\level}{1}{
\node[Sample, xshift=\samplewidth * \prev cm, draw,
yshift=\sampleheight * -2cm,
minimum width=\samplewidth cm,
fill=highcolor!\cmean!lowcolor]
(level\level samplemax\i) at (level\level sample0) {};
\coordinate (level\level samplemin\i) at (level\level samplemax\i);
\coordinate (level\level samplemean\i) at (level\level samplemax\i);
}{
\node[Sample, xshift=\samplewidth * \prev cm, draw,
yshift=\sampleheight * 0cm,
minimum width=\samplewidth cm,
fill=highcolor!\cmin!lowcolor]
(level\level samplemin\i) at (level\level sample0) {\smin};

\node[Sample, xshift=\samplewidth * \prev cm, draw,
yshift=\sampleheight * -1cm,
minimum width=\samplewidth cm,
fill=highcolor!\cmean!lowcolor]
(level\level samplemean\i) at (level\level sample0) {\smean};

\node[Sample, xshift=\samplewidth * \prev cm, draw,
yshift=\sampleheight * -2cm,
minimum width=\samplewidth cm,
fill=highcolor!\cmax!lowcolor]
(level\level samplemax\i) at (level\level sample0) {\smax};
}
};

\coordinate (level\level sampleminlabel)
at (level\level samplemin\levelblocks);
\coordinate (level\level samplemeanlabel)
at (level\level samplemean\levelblocks);
\coordinate (level\level samplemaxlabel)
at (level\level samplemax\levelblocks);
};

% arrows
\foreach \next in {2,...,\levels} {
\pgfmathtruncatemacro{\level}{\next-1}
\pgfmathsetmacro{\amplitude}{3pt * \level + 1.5pt}
\pgfmathsetmacro{\thislevelblocks}{\blocks / (4^(\level-1))}
\pgfmathsetmacro{\nextlevelblocks}{\blocks / (4^(\level))}
\foreach \block in {1,...,\nextlevelblocks} {
\pgfmathtruncatemacro{\a}{4*(\block-1)+1}
\pgfmathtruncatemacro{\b}{4*(\block-1)+4}
\pgfmathtruncatemacro{\c}{4*(\block-1)+2}
\draw [thick, decorate, decoration={brace, amplitude=\amplitude, mirror}]
([xshift=0.5pt]level\level samplemax\a.south west) --
([xshift=-0.5pt]level\level samplemax\b.south east);
\draw[thick, -stealth]
([yshift=-\amplitude]level\level samplemax\c.south east) --
(level\next samplemin\block .north);
};
};

% text
\foreach \level in {1,...,\levels} {
\pgfmathtruncatemacro{\decim}{(4^(\level - 1))}
% Level N
\node[xshift=-2.5cm, yshift=6pt, anchor=west] (foo) at
($(level\level sample0 |- level\level samplemean1)$)
{Level \level};
% Samples
\node[anchor=north, inner sep=0, font=\footnotesize] at (foo.south)
{\ifnumequal{\level}{1}{(${\color{red}N}$ values)}
{($3\cdot {\color{red}N / \decim}$ values)}};
};

\begin{scope}[anchor=west, inner sep=0, font=\footnotesize\itshape,
text depth=0ex, text height=1.1ex, draw]
\foreach \level in {2,...,\levels} {
\node[xshift=3pt] at (level\level sampleminlabel) { min };
\node[xshift=3pt] at (level\level samplemeanlabel) { mean };
\node[xshift=3pt] at (level\level samplemaxlabel) { max };
};
\end{scope}

\node[yshift=-0.8cm] at (foo.south) { $\vdots$ };

\end{tikzpicture}

\end{document}

-
show 1 more comment

Newton's rings.

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes}
\usepackage{amsmath}
\begin{document}
\pagecolor{yellow!50}
\begin{tikzpicture}[note/.style={rectangle callout, fill=#1}]
\foreach \x in {1,2,...,22}{
\draw[thick] (0,0) circle ({sqrt(\x)});
}
\fill[black!100] (0,0) circle (1);
\foreach \x in {23,24,...,28}{
\draw[black!30] (0,0) circle ({sqrt(\x)});
}
\node (v1) at (-1.014,-6.5) {\Large $m^\text{th}$ ring};
\draw[very thick,latex-](v1) -- (-1.014,-0.98);
\node (v2) at (1.414,-5.8) {\Large $\left(m+1\right)^\text{th}$ ring};
\draw[very thick,latex-](v2) -- (1.414,-1);
\draw[very thick,-](1.414,6) -- (1.414,0);
\draw[very thick,-](-1.414,6) -- (-1.414,0);
\draw[very thick,latex-latex](-1.414,5.8) -- (1.414,5.8);
\node at (0,6.1) {\Large $D_{m}$};
\draw[very thick,latex-latex](4.6904,7.4) -- (-4.6904,7.4);
\node at (0,7.7) {\Large $D_{m+21}$};
\node [draw,note=white!100, callout relative pointer={(2.05,-2.8)}] at (-7,3) {\Large Take first
\node (v3) at (-4.6904,8) {\Large $m+21$};
\draw[very thick,-](v3) -- (-4.6904,0);
\node [draw,note=white!100, callout relative pointer={(-2.05,-2.8)}] at (7,3) {\Large Take last
\node (v4) at (4.6904,8) {\Large $m+21$};
\draw[very thick,-](v4) -- (4.6904,0);
\end{tikzpicture}
\end{document}


Explanation:

We have an experiment in optics to measure the focal length of a lens using Newton's ring set up. This diagram is an illustration provided in the manual depicting the rings pattern. The radii of the rings are accurately equal to square root of 1,2,3..... Students take readings for only 21 rings and hence they are made dark for visibility.

-

Not very scientific and clearly not that awesome as the rest from here, but it was a big deal for me since a knew nothing about TikZ (I still know nothing, though :P). It's the ATDD cycle.

The code it's not pretty.

\documentclass{standalone}

\usepackage[spanish,es-noquoting]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes.misc}
\usetikzlibrary{positioning}
\usetikzlibrary{calc,intersections}

\begin{document}

\begin{tikzpicture}
\tikzset{normalstyle/.style={draw, drop shadow, fill=white, rectangle, inner sep=5pt, font=\bfseries, align=center}}
\tikzset{bubble/.style={draw, circle, fill=white, minimum width=5em}}

\def \offset{-5} % para que la linea que une rojo con verde sea diagonal

\draw[dotted, thick] ({90 + \offset - 1}:\radius*1.4) -- ({-90 + \offset -1 }:\radius*1.4);

\path[name path=circulo] (0, 0) circle (\radius);

% ELEGIR US
\node(elegir_us)[normalstyle, name path=path_elegir_us] at ({-173 + \offset}:\radius) {Elegir\\ User Story};

% START
\node (start) [node distance=0mm and 8mm, left=of elegir_us, circle, fill=black, minimum width=1pt]{};

% ESCRIBIR PRUEBAS
\node(escribir_pruebas)[normalstyle,name path=path_escribir_pruebas] at ({164 + \offset}:\radius) {Escribir pruebas\\ de aceptacion\\ para la Story};

% IMPLEMENTAR PRUEBA
\node(implementar_prueba)[normalstyle, name path=path_implementar_prueba] at ({132 + \offset}:\radius) {Implementar\\ prueba de\\    aceptacion};

% PRUEBA FALLANDO
\node(prueba_fallando)[name path=path_prueba_fallando,draw, drop shadow, fill=red, rectangle, inner sep=5pt, font=\bfseries, align=center] at ({90 + \offset}:\radius) {Prueba de\\ aceptacion\\ fallando};

% PRIMER TRIBUBBLE
\node(prueba1)[bubble,name path=path_prueba1] at ({52 + \offset}:\radius){Prueba};
\node(codigo1) [bubble, above right = 1mm and 5mm of prueba1.center] {Código};
\node(refactor1) [bubble,name path=path_refactor1, below right = 1mm and 5mm of prueba1.center] {Refactor};

% SEGUNDO TRIBUBBLE
\node(prueba2)[bubble,name path=path_prueba2] at ({0 + \offset}:\radius){Prueba};
\node(codigo2) [bubble, above right = 1mm and 5mm of prueba2.center] {Código};
\node(refactor2) [bubble, below right = 1mm and 5mm of prueba2.center] {Refactor};

% TERCER TRIBUBBLE
\node(prueba3)[bubble,name path=path_prueba3] at ({-52 + \offset}:\radius){Prueba};
\node(codigo3) [bubble,,name path=path_codigo3, above right = 1mm and 5mm of prueba3.center] {Código};
\node(refactor3) [bubble, below right = 1mm and 5mm of prueba3.center] {Refactor};

% PRUEBA PASANDO
\node(prueba_pasando)[name path=path_prueba_pasando, draw, drop shadow, fill=green, rectangle, inner sep=5pt, font=\bfseries, align=center] at ({-90 + \offset}:\radius) {Prueba de\\ aceptacion\\ pasando};

% REFACTOR
\node(refactor)[normalstyle, name path=path_refactorizar] at ({-128 + \offset}:\radius) {Refactorizar};

% ACEPTACION CLIENTE
\node(aceptacion_cliente)[normalstyle, name path=path_aceptacion_cliente] at ({-149 + \offset}:\radius) {Aceptacion\\ Cliente};

% INTERSECCIONES

% INTERSECCIÓN ELEGIR USER STORY
\path [name intersections={of=circulo and path_elegir_us,name=intELEGIRUS}];
\def \ELEGIRUSUP{intELEGIRUS-1}
\def \ELEGIRUSDOWN {intELEGIRUS-2}

% INTERSECCIÓN ESCRIBIR PRUEBAS
\path [name intersections={of=circulo and path_escribir_pruebas,name=intESCRIBIRPRUEBAS}];
\def \ESCRIBIRPRUEBASUP {intESCRIBIRPRUEBAS-1}
\def \ESCRIBIRPRUEBASDOWN {intESCRIBIRPRUEBAS-2}

% INTERSECCIÓN IMPLEMENTAR PRUEBA
\path [name intersections={of=circulo and path_implementar_prueba,name=intIMPLEMENTARPRUEBA}];
\def \IMPLEMENTARPRUEBAUP {intIMPLEMENTARPRUEBA-1}

% INTERSECCIÓN PRUEBA FALLANDO
\path [name intersections={of=circulo and path_prueba_fallando,name=intPRUEBAFALLANDO}];
\def  \PRUEBAFALLANDORIGHT {intPRUEBAFALLANDO-1}
\def \PRUEBAFALLANDOLEFT{intPRUEBAFALLANDO-2}

% INTERSECCIÓN TRIBUBBLE 1
\path [name intersections={of=circulo and path_prueba1,name=intPRUEBAUNO}];
\def \TRIBUBBLEUNOUP {intPRUEBAUNO-1}

\path [name intersections={of=circulo and path_refactor1,name=intREFACTORUNO}];
\def \TRIBUBBLEUNODOWN {intREFACTORUNO-2}

% INTERSECCIÓN TRIBUBBLE 2
\path [name intersections={of=circulo and path_prueba2,name=intPRUEBADOS}];

% INTERSECCIÓN TRIBUBBLE 3
\path [name intersections={of=circulo and path_codigo3,name=intCODIGOTRES}];
\def \TRIBUBBLETRESUP {intCODIGOTRES-1}

\path [name intersections={of=circulo and path_prueba3,name=intPRUEBA3}];
\def \TRIBUBBLETRESDOWN {intPRUEBA3-2}

% INTERSECCIÓN PRUEBA PASANDO
\path [name intersections={of=circulo and path_prueba_pasando,name=intPRUEBAPASANDO}];
\def \PRUEBAPASANDOLEFT {intPRUEBAPASANDO-1}
\def \PRUEBAPASANDORIGHT {intPRUEBAPASANDO-2}

% INTERSECCIÓN REFACTORIZAR
\path [name intersections={of=circulo and path_refactorizar,name=intREFACTORIZAR}];
\def \REFACTORIZARUP {intREFACTORIZAR-1}
\def \REFACTORIZARDOWN{intREFACTORIZAR-2}

% INTERSECCIÓN ACEPTACION CLIENTE
\path [name intersections={of=circulo and path_aceptacion_cliente,name=intACEPTACIONCLIENTE}];
\def \ACEPTACIONCLIENTEUP{intACEPTACIONCLIENTE-1}
\def \ACEPTACIONCLIENTEDOWN{intACEPTACIONCLIENTE-2}

% LAS FLECHAS EMPEZANDO POR START Y SIGUE EL CAMINO
\draw [->,bend left=15] (node cs:name=start, anchor=east) to (node cs:name=elegir_us, anchor=west);
\draw [->,bend left=15] (\ELEGIRUSUP) to (\ESCRIBIRPRUEBASDOWN);
\draw [->,bend left=15] (\ESCRIBIRPRUEBASUP) to (\IMPLEMENTARPRUEBADOWN);
\draw [->,bend left=15] (\IMPLEMENTARPRUEBAUP) to (\PRUEBAFALLANDOLEFT);
\draw [->,bend left=15] (\PRUEBAFALLANDORIGHT) to (\TRIBUBBLEUNOUP);
\draw [->,bend left=15] (\TRIBUBBLEUNODOWN) to (\TRIBUBBLEDOSUP);
\draw [->,bend left=15] (\TRIBUBBLEDOSDOWN) to (\TRIBUBBLETRESUP);
\draw [->,bend left=15] (\TRIBUBBLETRESDOWN) to (\PRUEBAPASANDORIGHT);
\draw [->,bend left=15] (\PRUEBAPASANDOLEFT) to (\REFACTORIZARDOWN);
\draw [->,bend left=15] (\REFACTORIZARUP) to (\ACEPTACIONCLIENTEDOWN);
\draw [->,bend left=15] (\ACEPTACIONCLIENTEUP) to (\ELEGIRUSDOWN);

% TDD Y ATDD
\node [above left = 10mm and 10mm of prueba_fallando.center, font=\Large\bfseries] {ATDD};
\node [above right = 10mm and 10mm of prueba_fallando.center, font=\Large\bfseries] {TDD};
\end{tikzpicture}

\end{document}

-

Configuration Space and Symbolic Subspace of a 2-Degrees of Freedom Robot

Depending on its configuration, it can either be in the symbolic state of penetrating the wall, or not penetrating it.

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes}
\usepackage{amsmath}
\begin{document}

\newdimen\xbase
\newdimen\ybase
\def\endDom{4}
\begin{tikzpicture}[domain=0:4]
\def\ColSymBorder{black}
\def\ColSymBorderTwo{black}
\def\ColSymFill{gray!70}
\def\ColSymFillTwo{gray!20}
\def\wallColor{gray!70}
\tikzstyle{block} = [draw, color=\ColSymBorder, ultra thick, fill=\ColSymFill, rectangle,  minimum height=3em, minimum width=6em];
\draw[color=\ColSymBorderTwo, ultra thick, fill=\ColSymFillTwo] (0,0) rectangle (4,4);
\draw (0,0) node[below,left]{$0^\circ$} -- (4,0) node[below,midway] {$\theta_1$} node[below,right] {$180^\circ$};
\draw (0,0) -- (0,4) node[left,midway] {$\theta_2$} node[left] {$180^\circ$};

\def\wallOffset{50pt}
\def\marginOff{5pt}

\draw[ultra thick,color=\ColSymBorder,fill=\ColSymFill, rounded corners=3pt]
(0,0.2) .. controls (0,1) and (0,2) ..   (0,3.8)
.. controls (0.3,3.5) and (0.8,3.1) .. (1,2.6)
.. controls (1.4,2.0) and (1.6,1.2) .. (2,0)
.. controls (1,0) and (0.5,0) .. (0.3,0)
.. controls (0.2,0.1) and (0.1,0.2) .. (0,0.3);
%.. controls (3,0) and (2,0) .. (0,0);

\newcounter{i}
\setcounter{i}{0}
\foreach \x in {1,100,...,180}{
\foreach \y in {1,100,...,180}{
%\ifthenelse{ {cos(\x)*40+50/cos(90-(\x+\y))} < 50}
%\ifthenelse{ \lengthtest{ {\f{\x}} pt < 50 pt}}

\pgfmathparse{ (
(cos(\x)*40pt+sin(\x+\y)*50pt)<(\wallOffset+\marginOff)) &&
(cos(\x)*40pt+sin(\x+\y)*50pt)>(\wallOffset-\marginOff))) ?1:0}
\ifnum\pgfmathresult>0
%penetrates the wall
\stepcounter{i}
\else
%out of the wall
\fi

}
}

\draw[thick,color=\ColSymBorder] (-2,1) -- (0,1);
\node[block] at (-3,1) {$s_0:$ penetratesWall};
\draw[thick,color=\ColSymBorderTwo] (6,3) -- (4,3);
\node[draw, color=\ColSymBorderTwo, ultra thick, fill=\ColSymFillTwo, rectangle,
minimum height=3em, minimum width=6em] at (7,3) {$s_1: \neg$penetratesWall};

%%%%%%%% PAINTING THE ROBOT STARTS HERE:

\newcommand*{\Robot}[4]{
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\pgfmathsetlengthmacro{\rw}{10} %width of base rectangle
\coordinate (base) at (#3,#4); %base coordinates

%\coordinage (cspace) at ({#1/180*\endDom},{#2/180*\endDom})

\path (base);
\pgfgetlastxy{\xbase}{\ybase};
\draw[thick,color=black] ({\xbase+1cm},{\ybase+3.0cm}) -- ({#1/180*\endDom},{#2/180*\endDom});
\draw[fill=black] ({#1/180*\endDom},{#2/180*\endDom}) circle (2pt);

\draw[thick,color=black] ({\xbase-1cm},{\ybase-0.5cm}) rectangle
({\xbase+3cm},{\ybase+3cm});

\draw[fill=\wallColor] ({\xbase+\wallOffset}, {\ybase-0.5cm}) rectangle
({\xbase+3cm}, {\ybase+3cm});

\pgfmathsetlengthmacro{\tx}{\rone*cos(\thetaone)+\xbase}
\pgfmathsetlengthmacro{\ty}{\rone*sin(\thetaone)+\ybase}
\coordinate (t1) at (\tx,\ty);

\pgfmathsetlengthmacro{\sx}{\rtwo*sin(\thetaone+\thetatwo)+\tx}
\pgfmathsetlengthmacro{\sy}{-\rtwo*cos(\thetaone+\thetatwo)+\ty}
\coordinate (t2) at (\sx,\sy);
\draw[ultra thick,black] (base) -- (t1);% node[below] {$\tx \ybase \xbase \ty$};
\draw[ultra thick,black] (t1) -- (t2);% node[below] {$\tx \ybase \xbase \ty$};

\draw[thick,color=black,fill=white!30] ({\xbase-0.5*\rw},{\ybase-0.5*\rw}) rectangle++ (\rw,\rw);
\draw[thick,color=black,fill=white!10] (t1) circle (2pt);
\draw[thick,color=black,fill=white!10] (t2) circle (2pt);

%% dashed line to represent link two at 0 degree
\pgfmathsetlengthmacro{\rtmp}{\rone }
\pgfmathsetlengthmacro{\tmpx}{\rtmp*sin(\thetaone)+\tx}
\pgfmathsetlengthmacro{\tmpy}{-\rtmp*cos(\thetaone)+\ty}
\coordinate (tmp1) at (\tmpx,\tmpy);
\draw[dashed,color=black] (t1) -- (tmp1);

%% dashed line to represent link one at 0 degree
\pgfmathsetlengthmacro{\tmpx}{\rone+\xbase}
\pgfmathsetlengthmacro{\tmpy}{\ybase}
\coordinate (tmp0) at (\tmpx,\tmpy);
\draw[dashed,color=black] (base) -- (tmp0);

\pgfmathsetlengthmacro{\tmpx}{\rone+\xbase}
\pgfmathsetlengthmacro{\tmpy}{\ybase}

\pgfmathsetlengthmacro{\tmpx}{0.9*\rone*cos(\thetaone)+\xbase}
\pgfmathsetlengthmacro{\tmpy}{0.9*\rone*sin(\thetaone)+\ybase}
\coordinate (tmp0t) at (\tmpx,\tmpy);

\pgfmathsetlengthmacro{\tmpx}{0.9*\rtwo*sin(\thetaone+\thetatwo)+\tx}
\pgfmathsetlengthmacro{\tmpy}{-0.9*\rtwo*cos(\thetaone+\thetatwo)+\ty}
\coordinate (tmp1t) at (\tmpx,\tmpy);

% ($(O)+(\StartAngle:-\Radius)$) is the center of the yellow circle

\draw[bend right,thick,->]  (tmp1) to node [auto] {$\theta_2$} (tmp1t);
\draw[bend right,thick,->]  (tmp0) to node [auto] {$\theta_1$} (tmp0t);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
}

\Robot{40}{40}{-4}{-4.5}
\Robot{70}{60}{1}{-4.5}
\Robot{110}{25}{6}{-4.5}
\end{tikzpicture}

\end{document}

-

Lifting of a random Delaunay triangulation to a hyperbolic paraboloid:

1. The planar delaunay triangulation was generated using C++ and CGAL
2. The data was visualized using asymptote

Here is the c++ code:

#include <fstream>
#include <sstream>
#include <vector>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/point_generators_2.h>
#include <CGAL/Triangulation_euclidean_traits_2.h>
#include <CGAL/Delaunay_triangulation_2.h>

using namespace CGAL;

typedef Exact_predicates_inexact_constructions_kernel   K;

typedef Delaunay_triangulation_2<K>                       Triangulation;
typedef Triangulation::Edge_iterator                        Edge_iterator;
typedef Triangulation::Point                                  Point;
typedef Triangulation::Vertex_handle                        Vertex;
typedef Triangulation::Face                                 Face;

typedef Creator_uniform_2<double,Point>         Creator;
typedef std::vector<Point>                        Point_set;
typedef std::vector<std::string>            Edges_str;

int main () {
int numPts = 50;
Point_set points;
points.reserve(numPts);

Random_points_in_disc_2<Point, Creator> randomGen (1.0 );
cpp0x::copy_n( randomGen, numPts, std::back_inserter(points));

Triangulation dt;
dt.insert(points.begin(),points.end());

int num_of_edges = 0;

Edges_str edges_str;
Edge_iterator eit;
for (eit = dt.finite_edges_begin(); eit != dt.finite_edges_end(); ++eit)
{
++num_of_edges;
std::ostringstream strs;
Triangulation::Face& f = *(eit->first);
int i = eit->second;
Vertex vs = f.vertex(f.cw(i));
Vertex vt = f.vertex(f.ccw(i));
strs << vs->point().x();
std::string vsx = strs.str();
strs.str("");
strs.clear();
strs << vs->point().y();
std::string vsy = strs.str();
strs.str("");
strs.clear();
strs << vt->point().x();
std::string vtx = strs.str();
strs.str("");
strs.clear();
strs << vt->point().y();
std::string vty = strs.str();

std::string curr_edge = "("+vsx+","+vsy+")\n"+"("+vtx+","+vty+")\n";
edges_str.push_back(curr_edge);
}

out << num_of_edges << "\n";
for (Edges_str::iterator it = edges_str.begin(); it != edges_str.end() ; ++it)
out << *it;
out.close();
return 0;
}


that produces the random Delaunay triangulation in the plane. The generated file random-delaunay-of-saddle.dat is used by the following asymptote code,

import graph3;
size(400);

surface operator cast(tube t) {
return t.s;
}

currentprojection=perspective(0.75,1.2,0.2);
real gridWidth=1.5;
pen  gridPen=blue;

real xy_level=-2.1;

real f (pair p){
real x = p.x;
real y = p.y;
return 0.5*(x^2-y^2);
}

struct Edge {
pair source; // Source point
pair target; // Target point
}

struct Edge3D {
triple source; // Source point
triple target; // Target point
}

// Read 2D points from file
int num_of_edges = fin;
write(num_of_edges);
Edge[] edges;
pair p1,p2;
for (int i=0; i<num_of_edges; ++i){
p1=fin;
p2=fin;
Edge e;
// Scaling the points, so the surface will be compatible with the non
// approximated one
e.source=2*p1;
e.target=2*p2;
edges.push(e);
}

for (int i=0 ; i<num_of_edges; ++i){
pair source=edges[i].source;
real psx=source.x;
real psy=source.y;
pair target=edges[i].target;
real ptx=target.x;
real pty=target.y;

triple Source1=(psx,psy,xy_level);
triple Target1=(ptx,pty,xy_level);
Edge3D e1;
e1.source=Source1;
e1.target=Target1;
floorEdges.push(e1);

triple Source2=(psx,psy,f((source.x,source.y)));
triple Target2=(ptx,pty,f((target.x,target.y)));
Edge3D e2;
e2.source=Source2;
e2.target=Target2;
}

for (int i=0; i<num_of_edges; ++i){
draw(tube(floorEdges[i].source--floorEdges[i].target,0.02*gridWidth),darkgreen);
}

real minVal = -2;
real maxVal = -minVal;

surface plane=surface(
new triple(pair p) {
return (p.x,p.y,xy_level);
},(1.2*minVal,1.2*minVal),(1.2*maxVal,1.2*maxVal)
);
draw(plane,gray+opacity(0.3));


to generate the image.

-

Here is a plot of the log barrier function B(x1, x2) = -ln x1 - ln x2.

Code (python to generate the lattice):

from numpy import linspace, pi, sin, cos, log
from scipy.optimize import bisect

# Code to generate patches
# (x(r,theta), y(r,theta), z(r,theta)), where
#    x(r,theta) = 1 - r cos(theta),
#    y(r,theta) = 1 - r sin(theta),
#    z(r,theta) = -log(x(r,theta)) - log(y(r,theta)).

PATCH = [(0,0), (2,0), (2,2), (0,2), (1,0), (2,1), (1,2), (0,1), (1,1)]
N     = 23
zmax  = 6
zmin  = -log(1)-log(1)

# Determine the value such that z = -log(x(r,theta)) - log(y(r,theta)).
def zinv(theta, z):
f = lambda r: -log(1 - r*cos(theta)) - log(1 - r*sin(theta)) - z
maxr = min(1/cos(theta), 1/sin(theta)) - 1e-6
return bisect(f, 0, maxr)

P = dict()
V = []

# Generate lattice points
for i, theta in enumerate(linspace(1e-6, pi/2-1e-6, N)):
for j, z in enumerate(linspace(zmin, zmax, N)):
r = zinv(theta, z)
x = 1 - r * cos(theta)
y = 1 - r * sin(theta)
z = - log(x) - log(y)
P[i,j] = len(V)
V.append((x,y,z))

# Write vertices
vfile = open("logbarrier_v.txt", "wt")
for v in V:
vfile.write("%0.8f %0.8f %0.8f\n" % v)
vfile.close()

# Write patches
pfile = open("logbarrier_p.txt", "wt")
for j in range(0, N-1, 2):
for i in range(0, N-1, 2):
for (di, dj) in PATCH:
pfile.write(str(P[i+di,j+dj]) + " ")
pfile.write("\n")
pfile.close()


and LaTeX:

\documentclass{standalone}

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\usepgfplotslibrary{patchplots}

\definecolor{plotfill}{RGB}{215,227,244}
\definecolor{plotblue}{RGB}{60,120,200}

\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0, xmax=1.2, ymin=0, ymax=1.4, zmin=0, zmax=6,
axis y line=center, axis x line=center, axis z line=center,
view/h=70, xtick={0, 1}, ytick={0}, ztick={0,5},
clip=false, axis on top=false, axis line style=thick, every tick/.style={black, thick}]

\node at (rel axis cs:1,0,0) [above, anchor=north west] {$x_1$};  %sloped like x axis,
\node at (rel axis cs:0,1,0) [above, anchor=west] {$x_2$};
\node at (rel axis cs:0,0,1) [above, anchor=south] {$B(x_1,x_2)$};

patch table=logbarrier_p.txt,colormap={custom}{color(0)=(plotfill) color(4)=(plotblue)}]
file {logbarrier_v.txt};

patch table=logbarrier_p.txt]
file {logbarrier_v.txt};

\draw [dashed] (axis cs: 1, 0, 0) -- (axis cs: 1, 1, 0);
\draw [dashed, opacity=0.33] (axis cs: 1, 1, 0) -- (axis cs: 0, 1, 0);
\draw [dashed, thick, opacity=0.33] (axis cs: 0, 0.2, 0) -- (axis cs: 0, 1.3, 0);
\draw [thick, opacity=0.33] (axis cs: 0, 1, 0.15) -- (axis cs: 0, 1, -0.15);
\node at (axis cs: 0, 1, 0) [anchor=south, opacity=0.33] {$1$};
\node at (axis cs: 0, 0, 0) [anchor=east] {$\mathbf{0}$};
\end{axis}
\end{tikzpicture}

\end{document}

-
show 1 more comment

Spontaneous Symmetry Breaking illustrated for a "mexican hat" potential.

Asymptote code:

import graph3;

size(200,200,IgnoreAspect);

currentprojection=perspective(5,2.7,3);

real f(pair z) {return -abs(z)^2+0.5*abs(z)^4;}

bbox3 b=limits(O,1.75(1,1,1));
currentlight=(1,-1,1);

picture surface=surface(f,(-1.3,-1.3),(1,1),nx=100,palegray);
draw(arc((0,0,-0.5),1,90,60,90,15),ArcArrow);

yaxis(Label("$\phi^\dagger\phi$",1),b,red,Arrow);
zaxis(Label("$V(\phi^\dagger\phi)$",1),b,red,Arrow);

-

It appears that I got the wrong end of the stick with this thread, as my images weren't created in LaTeX (I didn't realise that you could do this).

I've tried to rectify this by seeing if I could convert one of my original images to a LaTeX format from the original .eps files using Latexdraw; however, it turns out that my code is quite long (>0.5 M characters). So far I've only tried this for the nuclide map figure. Unfortunately, Latexdraw doesn't seem to be able to handle the original text very well, and I haven't figured out how to do it myself yet.

Anyway, here's a link to the code for the nuclide map if people want to play around with it. If someone does manage to put the text back, I'd be interested to know how you did it and with what software. For the time being I think I'll stick with SerifDraw and Inkscape to draw and convert my images from .svg to .eps, whilst I'm writing up my thesis, but may look to this for future work.

-
I really like both images, but the cool thing would be to make them in LaTeX (and Friends). –  Manuel Feb 7 at 12:26
This is not a proper answer to the question because the illustrations themselves were not created with LaTeX/PGF/TikZ/Asymptote/Metapost/PSTricks. –  marczellm Feb 7 at 12:45
show 3 more comments

Galvanic cell

\documentclass{article}

\usepackage[
figureposition = bottom
]{caption}
\usepackage{chemmacros}

\makeatletter
\providecommand*{\setfloatlocations}[2]{\@namedef{fps@#1}{#2}}
\makeatother
\setfloatlocations{figure}{htbp}

\captionsetup{
font = small,
labelfont = sc,
}

\def\anode{\ch{Zn}}
\def\anodeColour{gray!30}
\def\cathode{\ch{Cu}}
\def\cathodeColour{red!50}

\makeatletter
\define@key{cell}{anode}{\def\anode{\ch{#1}}}
\define@key{cell}{anodeColour}{\def\anodeColour{#1}}
\define@key{cell}{cathode}{\def\cathode{\ch{#1}}}
\define@key{cell}{cathodeColour}{\def\cathodeColour{#1}}
\makeatother

\newcommand*\cell[4][]{%
\setkeys{cell}{#1}
\def\basinWidth{#2 }
\def\basinHeight{#3 }
\def\waterHeight{#4}
% Basin
\psline(0,\basinHeight)(0,\waterHeight)
\pscustom[
fillstyle=solid,
fillcolor=cyan!70
]{%
\psline(0,\waterHeight)(\basinWidth,\waterHeight)
\psline(0,\waterHeight)(0,1)
\psarc(1,1){1}{180}{270}
\psline(1,0)(!\basinWidth 1 sub 0)
\psarc(!\basinWidth 1 sub 1){1}{270}{360}
\psline(\basinWidth,1)(\basinWidth,\waterHeight)
\closepath
}
\psline(\basinWidth,\waterHeight)(\basinWidth,\basinHeight)
% Membrane
\psline[
linestyle=dashed
](!\basinWidth 2 div 0)%
(!\basinWidth 2 div \waterHeight)
% Cathode
\pspolygon[
fillstyle=solid,
fillcolor=\cathodeColour
](!\basinWidth 4 div 1 sub 1)%
(!\basinWidth 4 div 1 sub \basinHeight 1 sub)%
(!\basinWidth 4 div 1 add \basinHeight 1 sub)%
(!\basinWidth 4 div 1 add 1)
\rput(!\basinWidth 4 div \basinHeight 2 div){\cathode\xspace}
% Anode
\pspolygon[
fillstyle=solid,
fillcolor=\anodeColour
](!3 \basinWidth mul 4 div 1 sub 1)%
(!3 \basinWidth mul 4 div 1 sub \basinHeight 1 sub)%
(!3 \basinWidth mul 4 div 1 add \basinHeight 1 sub)%
(!3 \basinWidth mul 4 div 1 add 1)
\rput(!3 \basinWidth mul 4 div \basinHeight 2 div){\anode}
% Wires with current
\rput(!\basinWidth 4 div 1 add \basinHeight){$+$}
\psline(!\basinWidth 4 div \basinHeight 1 sub)%
(!\basinWidth 4 div \basinHeight)
\psarc(!\basinWidth 4 div 1 add \basinHeight){1}{90}{180}
\psline(!\basinWidth 4 div 1 add \basinHeight 1 add)%
(!\basinWidth 1 sub 2 div \basinHeight 1 add)
\pscircle(!\basinWidth 2 div \basinHeight 1 add){0.5}
\rput(!\basinWidth 2 div \basinHeight 1 add){$U$}
\psline(!3 \basinWidth mul 4 div 1 sub \basinHeight 1 add)%
(!\basinWidth 1 add 2 div \basinHeight 1 add)
\psarc(!3 \basinWidth mul 4 div 1 sub \basinHeight){1}{0}{90}
\psline(!3 \basinWidth mul 4 div \basinHeight 1 sub)%
(!3 \basinWidth mul 4 div \basinHeight)
\rput(!3 \basinWidth mul 4 div 1 sub \basinHeight){$-$}
% Electron movement
\rput(!3 \basinWidth mul 1 add 8 div \basinHeight 3 2 div add)%
{\ch{<-[$\el$]}}
\rput(!5 \basinWidth mul 2 sub 8 div \basinHeight 3 2 div add)%
{\ch{<-[$\el$]}}
}

\psset{unit = 0.5\psunit}

\begin{document}

% Without optional arguments; the stardard' version.
\begin{figure}
\centering
\begin{pspicture}(15,11.9)
\cell{15}{10}{8}
\end{pspicture}
\caption{Galvanic cell where \anode{} is the anode and \cathode{} is the cathode.}
\end{figure}

% With optional arguments; a non-stardard' version.
\begin{figure}
\centering
\begin{pspicture}(15,11.9)
\cell[
anode = Cu,
anodeColour = red!50,
cathode = Ag,
cathodeColour = gray!20
]{15}{10}{8}
\end{pspicture}
\caption{Galvanic cell where \ch{Cu} is the anode and \ch{Ag} is the cathode.}
\end{figure}

\end{document}


-

Note: There is a screenshot of only the first half life of a nucleus but there are five half lifes for each version (but it can very easily be changed).

First version

\documentclass[
dvipsnames
]{article}

\usepackage{lmodern}
\usepackage[
hmargin = 2.4cm,
vmargin = 3cm
]{geometry}
\usepackage{fancyhdr}
\usepackage{pst-plot}
\usepackage[
locale = DE
]{siunitx}
\usepackage{xfrac}
\usepackage{totcount}

%%% Constants %%%

\ExplSyntaxOn
\cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff

\def\HalveringerA{\calc{\Halveringer-1}}
\def\HalveringerB{\calc{\Halveringer+1}}
\def\konstA{\calc{10*2^(-\iA)}}
\def\konstI{\num{\calc{10*\konstA}}}
\def\konstB{\calc{2^(-\Halveringer)}}
\def\konstC{\calc{16*2^(-\iA)}}
\def\konstD{\calc{16-\konstC}}
\def\konstE{\calc{2*\Halveringer+0.25}}
\def\konstF{\calc{\konstE+0.25}}
\def\konstG{\calc{\konstE-0.25}}
\def\konstH{\calc{\konstE+0.55}}

%%% Definitions %%%

\pscircle[
fillstyle = solid,
fillcolor = yellow,
linestyle = none
](0,0){0.125}
\pswedge*(0,0){0.125}{0}{60}
\pswedge*(0,0){0.125}{120}{180}
\pswedge*(0,0){0.125}{240}{300}
\pscircle*[
linecolor = yellow
](0,0){0.0375}
\pscircle*(0,0){0.025}
}
\pscircle*[
linecolor = SeaGreen
](0,0){0.125}
}

\newcommand*\halveringer[1]{%
\def\Halveringer{#1}
\begin{pspicture}(-1.75,-0.7)(\konstH,11.05)
\multido{\iA = 0+1, \rC = 0.25+2}{\Halveringer}{%
\multido{\rA = \rC+0.5}{4}{%
\multido{\rB = 0.27+0.635}{\konstC}{%
}%
}%
}
\multido{\iA = 0+1, \rC = 0.25+2}{\Halveringer}{%
\multido{\rA = \rC+0.5}{4}{%
\multido{\rB = 9.795+-0.635}{\konstD}{%
}%
}%
}
\multido{\iA = 0+1}{\Halveringer}{%
\psline(!2   \iA\space mul     \konstA)%
(!2 1 \iA\space add mul \konstA)%
(!2 2 \iA\space mul add \konstA\space 2 div)%
}
\psline(!2 \Halveringer\space mul 10 \konstB\space mul)%
(!2 \Halveringer\space mul 0)
\psaxes[
ticks = none,
labels = none,
arrowinset = 0.05,
arrowscale = 1.6,
arrowlength = 1.8
]{->}(0,0)(-0.3,-0.3)(\konstF,10.5)[$t$,0][Radioactive nuclei~(\si{\percent}),90]
\psplot[
algebraic,
linecolor = red,
linewidth = 1.5pt
]{0}{\konstG}{10*0.5^(0.5*x)}
\psxTick(2){T_{\sfrac{1}{2}}}
\multido{\iA = 4+2, \iB = 2+1}{\HalveringerA}{%
\psxTick(\iA){\iB \cdot T_{\sfrac{1}{2}}}%
}
\multido{\iA = 0+1}{\HalveringerB}{%
\psyTick(\konstA){\konstI}%
}%
\end{pspicture}%
}

\pagestyle{fancy}
\regtotcounter{page}
\cfoot{
\ifnum \totvalue{page} > 1 \relax
\thepage
\else
%
\fi
}

\begin{document}

%\begin{figure}[htbp]
% \centering
%  \begin{pspicture}(-2.4,-1.4)(2.4,2.9)
%    \pspolygon[
%      fillstyle = solid,
%      fillcolor = yellow,
%      linewidth = 5\pslinewidth
%    ](2.875;-30)(2.875;90)(2.875;210)
%    \pswedge*(0,0){1.25}{0}{60}
%    \pswedge*(0,0){1.25}{120}{180}
%    \pswedge*(0,0){1.25}{240}{300}
%    \pscircle*[
%      linecolor = yellow
%    ](0,0){0.375}
%    \pscircle*(0,0){0.25}
%  \end{pspicture}
%\end{figure}
%
%\begin{figure}[htbp]
% \centering
%  \begin{pspicture}(-1.8,-1.9)(1.8,1.9)
%    \psframe[
%      fillstyle = solid,
%      fillcolor = yellow,
%      linecolor = gray
%    ](-2,-2)(2,2)
%    \pswedge*(0,0){1.75}{0}{60}
%    \pswedge*(0,0){1.75}{120}{180}
%    \pswedge*(0,0){1.75}{240}{300}
%    \pscircle*[
%      linecolor = yellow
%    ](0,0){0.5}
%    \pscircle*(0,0){0.35}
%  \end{pspicture}
%\end{figure}
%\newpage

\multido{\iK = 1+1}{5}{%
\begin{center}
\halveringer{\iK}
\end{center}
}

\end{document}


Second version

\documentclass[
dvipsnames
]{article}

\usepackage{lmodern}
\usepackage[
hmargin = 2.4cm,
vmargin = 3cm
]{geometry}
\usepackage{fancyhdr}
\usepackage{
pst-plot
}
\usepackage[
locale = DE
]{siunitx}
\usepackage{xfrac}
\usepackage{totcount}

%%% Constants %%%

\ExplSyntaxOn
\cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff

\def\maerkerX{\calc{1.5*\i+0.75}}
\def\maerkerYa{\calc{10*2^(-\i)}}
\def\maerkerYb{\num{\calc{100*2^(-\i)}}}

\def\halveringerB{\calc{\Halveringer-1}}
\def\halveringerC{\calc{\Halveringer+1}}
\def\konstA{\calc{1.5*\i+0.25}\space}
\def\konstB{\calc{32*2^(-\i)}}
\def\konstC{\calc{32-\konstB}}
\def\konstD{\calc{1.5*\halveringerC+0.75}}
\def\konstE{\calc{\konstD-0.75}}
\def\konstF{\calc{\konstD+0.3}}

%%% Definitions %%%

\psscalebox{0.0125}{%
\pscircle[
fillstyle = solid,
fillcolor = yellow,
linestyle = none
](0,0){5}
\pswedge*(0,0){5}{0}{60}
\pswedge*(0,0){5}{120}{180}
\pswedge*(0,0){5}{240}{300}
\pscircle*[
linecolor = yellow
](0,0){1.5}
\pscircle*(0,0){1}
}
}

\pscircle*[
linecolor = SeaGreen
](0,0){0.0625}
}

\def\henfald{rand 301 mod 50 div round 50 div }
\def\simpel#1{!#1 \henfald add \henfald \i\space 5 mul 16 div add 0.121 add }

\newcommand*\halveringer[1]{%
\def\Halveringer{#1}
\begin{pspicture}(-1.75,-0.65)(\konstF,11.3)
\psframe[
linestyle = none,
](0,0)(\konstE,10.25)
\multido{\i = 0+1}{\halveringerC}{%
\psframe[
dimen = middel,
linecolor = NavyBlue,
linewidth = 1pt,
](\konstA,0)(!\konstA 1 add \maerkerYa)%
}
\multido{\i=0+1}{\halveringerC}{%
\psframe[
dimen = middel,
linecolor = NavyBlue,
linewidth = 1pt,
](\konstA,10)(!\konstA 1 add \maerkerYa)%
}
\multido{\i = 0+1}{\halveringerC}{%
\rput(\konstA,0){%
\multido{\i = 0+1}{\konstB}{%
}%
}
\rput(\konstA,\maerkerYa){%
\multido{\i = 0+1}{\konstC}{%
}%
}%
}
\psaxes[
ticks = none,
labels = none,
arrowinset = 0.05,
arrowscale = 1.6,
arrowlength = 1.8
]{->}(0,0)(-0.3,-0.3)(\konstD,10.75)[$t$,0][Radioactive nuclei~(\si{\percent}),90]
\psplot[
algebraic,
linecolor = red,
linewidth = 1.5pt
]{0.75}{\konstE}{10*0.5^(2*(x-0.75)/3)}
\psxTick(0.75){\text{start}}
\ifnum\Halveringer>0\relax
\psxTick(2.25){T_{\sfrac{1}{2}}}
\multido{\i = 2+1}{\halveringerB}{%
\psxTick(\maerkerX){\i \cdot T_{\sfrac{1}{2}}}%
}
\multido{\i = 0+1}{\halveringerC}{%
\psyTick(\maerkerYa){\maerkerYb}%
}%
\fi%
\end{pspicture}%
}

\pagestyle{fancy}
\regtotcounter{page}
\cfoot{
\ifnum \totvalue{page} > 1 \relax
\thepage
\else
%
\fi
}

\begin{document}

\multido{\iK = 0+1}{6}{%
\begin{center}
\halveringer{\iK}
\end{center}
}

\end{document}


P.S. The macro names are is Danish but I hope it is understandable none the less.

-
show 2 more comments

The butterfly curve.

\documentclass{article}
\usepackage{xpicture}
\begin{document}

\DIVIDE{1}{12}{\invXII}
\MULTIPLY{12}{\numberTWOPI}{\phione}
\MULTIPLY{12}{64}{\divisions}

\COMPOSITIONfunction{\EXPfunction}{\COSfunction}{\Afunction}
\SCALEVARIABLEfunction{4}{\COSfunction}{\Bfunction}
\SCALEVARIABLEfunction{\invXII}{\SINfunction}{\cfunction}
\POWERfunction{\cfunction}{5}{\Cfunction}
\LINEARCOMBINATIONfunction{1}{\Afunction}{-2}{\Bfunction}{\ABfunction}
\SUBTRACTfunction{\ABfunction}{\Cfunction}{\ABCfunction}
\PRODUCTfunction{\SINfunction}{\ABCfunction}{\Xfunction}
% x=(sin t)(exp(cos t)-2 cos 4t + (sin(t/12))^5)
\PRODUCTfunction{\COSfunction}{\ABCfunction}{\Yfunction}
% y=(cos t)(exp(cos t)-2 cos 4t + (sin(t/12))^5)
\PARAMETRICfunction{\Xfunction}{\Yfunction}{\butterfly}

\setlength{\unitlength}{1cm}

\centering
\begin{Picture}(-4,-3)(4,4)
\PlotParametricFunction[\divisions]\butterfly{0}{\phione}
\end{Picture}
$\mathbf{f}(t)= \left(\mathrm{e}^{\cos t}-2\cos 4t+\sin^5 \frac{t}{12}\right) (\sin t,\cos t)$

\end{document}


-

Below I made a basic diagram to illustrate (vertical) interlinkages such as in a supply chain in an economy.

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\draw (0,0) -- (6,0);
\draw (0,0) -- (0,-1); \draw (6,0) -- (6,-1);
\draw (0,0) rectangle (1,-1);
\draw (1,0) rectangle (2,-1);
\draw (2,0) rectangle (3,-1);
\draw (3,0) rectangle (4,-1);
\draw (4,0) rectangle (5,-1);
\draw (5,0) rectangle (6,-1);
\draw [yellow, line width=6] (0,-1)--(1,-1);
\draw [red, line width=6] (1,-1)--(2,-1);
\draw [green, line width=6] (2,-1)--(3,-1);
\draw [pink, line width=6] (3,-1)--(4,-1);
\draw [purple, line width=6] (4,-1)--(5,-1);
\draw [lightgray, line width=6] (5,-1)--(6,-1);
\draw[<->,thick,cyan] (0.5,-1.5) to [out=305,in=225] (1.5,-1.5);
\draw[<->,thick,cyan] (1.5,-1.5) to [out=305,in=225] (2.5,-1.5);
\draw[<->,thick,cyan] (2.5,-1.5) to [out=305,in=225] (3.5,-1.5);
\draw[<->,thick,cyan] (3.5,-1.5) to [out=305,in=225] (4.5,-1.5);
\draw[<->,thick,cyan] (4.5,-1.5) to [out=305,in=225] (5.5,-1.5);
\node at (0.5,0.3) {I};
\node at (1.5,0.3) {II};
\node at (2.5,0.3) {III};
\node at (3.5,0.3) {IV};
\node at (4.5,0.3) {V};
\node at (5.5,0.3) {VI};
\end{tikzpicture}
\end{document}


-