2

I am aware that there is myriad of posts dealing with the intersection of objects in tikz, but I haven't found one that shows how to intersect two paths, so far. I would like to either shade or hatch the intersection of two blobs:

\documentclass{standalone}
\usepackage{tikz,pgfplots}
\usetikzlibrary{hobby,intersections,fillbetween,patterns}

\begin{document}

\begin{tikzpicture} \path[name path = A,draw,use Hobby shortcut,closed=true, fill=blue] (0,2) .. (3,3) .. (4,-3) .. (5,1); \path[name path = B,draw,use Hobby shortcut,closed=true, fill=red,xshift=3cm, yshift=-1cm, fill opacity=.5] (.5,.5) .. (2,4) .. (.5,4) .. (-1,2); \end{tikzpicture}

\end{document}

enter image description here

Since couldn't see how to use \clip with \path, and following the examples on this post, I thought fillbetween might have been the answer, but adding

\tikzfillbetween[of=A and B,split] {pattern=north west lines};

produces

enter image description here

and I think I see why. How can I hatch/shade the intersection only?

Mogu
  • 321

1 Answers1

1

If I understood correctly, a solution with \clip

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{hobby,patterns}
\begin{document}
\begin{tikzpicture}
\path[use Hobby shortcut,closed=true, fill=red,xshift=3cm, yshift=-1cm,fill opacity=0.5]
        (0.5,0.5) .. (2,4) .. (.5,4) .. (-1,2);
\path[use Hobby shortcut,closed=true, fill=blue]
        (0,2) .. (3,3) .. (4,-3) .. (5,1);
\begin{scope}
\clip[use Hobby shortcut, closed=true, xshift=3cm, yshift=-1cm]
        (0.5,0.5) .. (2,4) .. (.5,4) .. (-1,2);
\path[use Hobby shortcut,closed=true, pattern=north west lines,preaction={fill=red,opacity=0.5}]
        (0,2) .. (3,3) .. (4,-3) .. (5,1);
\end{scope}
\path[draw,use Hobby shortcut,closed=true]
        (0,2) .. (3,3) .. (4,-3) .. (5,1);
\path[draw,use Hobby shortcut,closed=true,xshift=3cm, yshift=-1cm]
        (0.5,0.5) .. (2,4) .. (.5,4) .. (-1,2); 
\end{tikzpicture}
\end{document}

enter image description here

polyn
  • 5,614
  • Perfect! Yes, I didn't quite know how to implement the \clip command. Thanks for the example! – Mogu Jul 01 '21 at 08:49