6

Let's assume we have this irregular shaped object:


Minimum Working Example (MWE):

\documentclass[margin=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
  \begin{tikzpicture}
    \draw plot[domain=0:350, smooth cycle] (\x:2+rnd*0.9);
  \end{tikzpicture}
\end{document}

Screenshot of the result:

Screenshot of the result


Description of the issue:

How can I draw the exactly same shape around the initial one, but with a bigger radius to create some "skin" like layer around the first one?

In fact I need two more shapes of those, each of them with a bigger radius than the previous one. Furthermore, the shapes should have some fill (either color or better: Dots).

Background:

I want to visualize a soil particle where a biofilm is growing on the surface of the particle. In the end it could look like part of the following image, but in my case where the biofilm is growing around the whole particle:

Biofilm structure

In best case, we could add some arrow on the right side to visualize the streaming gas... :-)


Update (2019/02/03):

This approach inspired by an answer of "Surrounding an arbitrary path?" based on the definition of mypath is throwing errors:

\documentclass[tikz,border=3cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\tikzset{%
  draw seam allowance/.style 2 args={
    preaction={line width=1mm,line join=round,double distance=#1*2,draw=#2},
  },
  seam allowances/.style={%
    preaction={clip},
    preaction={draw seam allowance/.list={#1}},
    draw,%fill=white,
  },
  seam allowances/.default={{{2cm}{blue}}},
  invclip/.style={
    clip,
    insert path={
      {[reset cm] (-16000pt,-16000pt)  -| (16000pt,16000pt) -| cycle}
    },
  },
}
\begin{document}
\begin{tikzpicture}
  \def\mypath{
    (\x:2+rnd*0.9) -- cycle
  }
  \begin{scope}
    \begin{pgfinterruptboundingbox}
      \path [invclip] \mypath;
    \end{pgfinterruptboundingbox}
    \draw [seam allowances={{4cm}{black},{2cm}{black}},line width=2mm]
    \mypath ;
  \end{scope}
\end{tikzpicture}
\end{document}
Stefan Pinnow
  • 29,535
Dave
  • 3,758

1 Answers1

5

The problem with your code is that \mypath is not a proper path. This is a proposal to fix this (presumably based on this answer). We build up a list of random coordinates and then use them in the path.

\documentclass[tikz,border=3cm]{standalone}
\tikzset{%
  draw seam allowance/.style 2 args={
    preaction={line width=1mm,line join=round,double distance=#1*2,draw=#2},
  },
  seam allowances/.style={%
    preaction={clip},
    preaction={draw seam allowance/.list={#1}},
    draw,%fill=white,
  },
  seam allowances/.default={{{2cm}{blue}}},
  invclip/.style={
    clip,
    insert path={
      {[reset cm] (-16000pt,-16000pt)  -| (16000pt,16000pt) -| cycle}
    },
  },
}
\begin{document}
\begin{tikzpicture}
  \pgfmathsetseed{12}
  \foreach \X in {0,20,...,340} 
  {\ifnum\X=0
  \xdef\mypath{(\X:2+rnd*0.9)}
  \else
  \xdef\mypath{\mypath (\X:2+rnd*0.9)}
  \fi
  }
  \begin{scope}
    \begin{pgfinterruptboundingbox}
      \path [invclip] \mypath;
    \end{pgfinterruptboundingbox}
    \draw [seam allowances={{4cm}{black},{2cm}{black}},line width=2mm]
    plot[smooth cycle] coordinates {\mypath };
  \end{scope}
\end{tikzpicture}
\end{document}

enter image description here

  • 1
    Thank you very much! I could not use Ulrike's answer because it is only valid for two shapes, no? – Dave Feb 03 '19 at 19:37
  • Just one last question: How could I store the current image? All few minutes I recompile this formula my shape will change... – Dave Feb 03 '19 at 19:54
  • 1
    @Dave Does adding \pgfmathsetseed{12} (say) after \begin{tikzpicture} solve this issue? –  Feb 03 '19 at 19:58