TikZ-PGF – Using Path Exclusion for Compound Shapes with Pathfinder Functionality in TikZ

clipfillpath-clippingpathstikz-pgf

On Adobe Illustrator, it is very easy to use Pathfinder to create compound shapes by (using the path exclude function with the shape to be retained in the back layer and all paths to be removed in above layers):

enter image description here

Clearly, we can use a basic application of clipping in an attempt to recreate this with Tikz, which works fine if we are not concerned with drawing borders:

enter image description here

\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

%   \clip (0,0) circle (1);

    \fill[red!20] (0,0) circle (1);

    \begin{scope}[rotate=-60]
        \fill[white] (0,-0.1) rectangle (1.5,0.1);
    \end{scope}

    \begin{scope}[rotate=-120]
        \fill[white] (0,-0.1) rectangle (1.5,0.1);
    \end{scope}

    \fill[white] (-1.5,-0.1) rectangle (1.5,0.1);
    
    \end{tikzpicture}
\end{document}

However, if we are concerned with draw borders, it then becomes a lot more interesting and cannot achieve the desired solution easily. Best attempt with a heap of issues (accounting for the line width on the clip (currently it cuts into the line) and overlapping lines from the excluded regions).

enter image description here

\documentclass[12pt,tikz, border = 1cm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

    \clip (0,0) circle (1);

    \filldraw[fill=red!10,draw=blue] (0,0) circle (1);

    \begin{scope}[rotate=-60]
        \filldraw[anchor=east,fill=white,draw=blue] (0,-0.1) rectangle (1.5,0.1);
    \end{scope}

    \begin{scope}[rotate=-120]
        \filldraw[anchor=east,fill=white,draw=blue] (0,-0.1) rectangle (1.5,0.1);
    \end{scope}

    \filldraw[fill=white,draw=blue] (-1.5,-0.1) rectangle (1.5,0.1);
    
    \end{tikzpicture}
\end{document}

Is there a way for us to achieve the desired result (first image, second circle with excluded regions but draw available) but with TikZ? Can we maybe do this by clipping a path, then filling that path, but also having that path available to draw?

Best Answer

The spath3 library is very powerful and well suited to this question. But in this particular case, we can get a similar result by cheating with a double line like this:

\documentclass[tikz,border=7pt]{standalone}
\begin{document}
  \begin{tikzpicture}
    \clip[postaction={fill=red!20, draw=blue, thick}]
      (0,0) circle (1cm)
    ;
    \path[draw=blue, double, double distance=2mm]
      (-2,0) -- (2,0)
      (0,0) -- (-60:2)
      (0,0) -- (-120:2)
    ;
  \end{tikzpicture}
\end{document}

enter image description here