[Tex/LaTex] TikZ clip shapes using several (built in) shapes

path-clippingtikz-pgf

I'm looking for a way to draw one image composed of a union of multiple cloud shapes. The following MWE:

\documentclass{standalone}

\usepackage{tikz}

\usetikzlibrary{positioning}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}
    \newcommand{\CloudDist}{1.8}

    \tikzstyle {cloudkeys} = [cloud puffs=30, cloud puff arc=150, aspect=1.25, inner sep=0.7cm,] 
    \tikzstyle {mycloud}   = [draw, cloud, cloudkeys, fill=blue!25, nearly opaque] 

    \coordinate (cloud 0);
    \coordinate [right=\CloudDist cm of cloud 0] (cloud 1);
    \coordinate [right=\CloudDist cm of cloud 1] (cloud 2);

    \foreach \x in {0,1,2} {
        \node [mycloud] at (cloud \x) (local map cloud shape \x) {};
    }
\end{tikzpicture}
\end{document}

produces this figure:

WME Result

but the desired result is something like this one:

enter image description here

I found some answers that almost showed me how to do it.

  • Answers in this question shows how to clip shapes with another (single) shape;
  • Answers in two other questions (here and here) shows how to invert a clip selection using basic shapes or paths.

I think what want to do can be achieved with a mix of these answers, but I couldn't do it myself. I would appreciate if someone can show me how to draw this figure.

Best Answer

You can use clipping, but the other solution is simpler. Note that the nodes anchors do not form a rectangle.

\documentclass{standalone}

\usepackage{tikz}

\usetikzlibrary{positioning}
\usetikzlibrary{shapes}

\begin{document}

\begin{tikzpicture}
    \newcommand{\CloudDist}{1.8}

    \tikzstyle {cloudkeys} = [cloud puffs=30, cloud puff arc=150, aspect=1.25, inner sep=0.7cm,] 
    \tikzstyle {mycloud}   = [draw, cloud, cloudkeys, fill=blue!25, nearly opaque] 

    \coordinate (cloud 0);
    \coordinate [right=\CloudDist cm of cloud 0] (cloud 1);
    \coordinate [right=\CloudDist cm of cloud 1] (cloud 2);

    \path (cloud 0) -- (cloud 1) coordinate[midway] (cloud edge 1);
    \path (cloud 1) -- (cloud 2) coordinate[midway] (cloud edge 2);

    \begin{scope}
      \node[cloud, cloudkeys,outer sep=2pt] (temp) at (cloud 0) {};% invisible, used for clip rectangle
      \clip (temp.south -| temp.west) rectangle (temp.north -| cloud edge 1);
      \node [mycloud] at (cloud 0) (local map cloud shape 0) {};
    \end{scope}
    \begin{scope}
      \node[cloud, cloudkeys,outer sep=2pt] (temp) at (cloud 1) {};% invisible, used for clip rectangle
      \clip (temp.south -| cloud edge 1) rectangle (temp.north -| cloud edge 2);
      \node [mycloud] at (cloud 1) (local map cloud shape 1) {};
    \end{scope}
    \begin{scope}
      \node[cloud, cloudkeys,outer sep=2pt] (temp) at (cloud 2) {};% invisible, used for clip rectangle
      \clip (temp.south -| cloud edge 2) rectangle (temp.north -| temp.east);
      \node [mycloud] at (cloud 2) (local map cloud shape 2) {};
    \end{scope}

\end{tikzpicture}
\end{document}

demo