2

I would like to fill the intersection between the disk and the form delimited by the folling plot :

\documentclass[11pt]{report}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\draw[name path=k1,fill=blue!30] plot[smooth cycle] coordinates 
{(0,0) (1,1) (3,0) (5,1) (7,-1.5) (4,-3) (2,-2) (0,-1)};
\draw [name path=k2] (1,0) circle (2cm);
\draw [red,very thick,intersection segments={of=k1 and k2,sequence={L1}}];
\draw [blue,very thick,intersection segments={of=k1 and k2,sequence={L3}}];
\draw [green,very thick,intersection segments={of=k1 and k2,sequence={R3}}];
\draw [green,very thick,intersection segments={of=k1 and k2,sequence={R2}}];
\end{tikzpicture}
\end{document}

I don't manage to pick the right segments to achieve filling the intersection correctly.

Alenanno
  • 37,338
jadou
  • 213
  • 1
    Please, give a fully compilable code. – AndréC Oct 21 '20 at 14:04
  • I have reopened the question as the suggested duplicate simply offered an alternative solution using \clip that can be used in this case. While it's a valid alternative (if the OP decides to use it), it doesn't make this question a duplicate. – Alenanno Oct 21 '20 at 23:21

2 Answers2

2

Well, I'm not sure if intersection segments is a bit buggy, because some paths are being added that shouldn't be there and that make this process harder than it should be. Or maybe it's just hard to use.

See here:

enter image description here

As you can notice, we could do L1--L0--R0 but these lines create issues as without them, the fills will have thin holes (the lines that my arrows point to will not be there and the blue beneath would be slightly visible), and with them, you'll have lines in the middle of the fill. Neither is ideal.

Therefore a way to circumvent this is that you draw the other intersection, but in a way that draws the final result you were looking for. The part I'm drawing here is actually the blue part.

Output

enter image description here

Code

\documentclass[margin=10pt, tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17} % <--- latest version
\usepgfplotslibrary{fillbetween}

\begin{document} \begin{tikzpicture} \draw[name path=k1,fill=orange!30] plot[smooth cycle] coordinates {(0,0) (1,1) (3,0) (5,1) (7,-1.5) (4,-3) (2,-2) (0,-1)}; \draw[name path=k2] (1,0) circle (2cm);

\fill[blue!30,draw=black,
    intersection segments={of=k1 and k2,sequence={L2--R3}}];

\end{tikzpicture} \end{document}

Alenanno
  • 37,338
1

If I understand correctly, you want to achieve the result from below (and your question is a duplicate). Maybe I do not understand, as you want the intersection points for something!? -also you are not using PGFPlots or fillbetween at all.

\documentclass[tikz, border=1 cm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw (1,0) circle (2cm);
\draw plot[smooth cycle] coordinates 
{(0,0) (1,1) (3,0) (5,1) (7,-1.5) (4,-3) (2,-2) (0,-1)};
\clip (1,0) circle (2cm);
\fill[blue!30] plot[smooth cycle] coordinates 
{(0,0) (1,1) (3,0) (5,1) (7,-1.5) (4,-3) (2,-2) (0,-1)};
\end{tikzpicture}
\end{document}

intersection filled

  • He is using pgfplots: name path is being allowed by the fillbetween library. Then you have intersection segments: both this and the library require pgfplots. Also, it's not a duplicate, the OP is asking about intersection segments. You can offer an alternative solution, but that doesn't make this a duplicate, therefore I have reopened it. – Alenanno Oct 21 '20 at 23:20