如何在两条曲线之间进行裁剪?

如何在两条曲线之间进行裁剪?

我必须在两条曲线之间进行填充,就像这张照片一样

在此处输入图片描述

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{patterns,calc,positioning,shapes}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}[ thick]
\draw[name path=A] (-7.5,-1) .. controls (-3,5.5) and (3,5.5) .. (7.5,-1);
\draw [name path=B](-6,-1) .. controls (-2,4) and (2,4) .. (6,-1);
\tikzfillbetween[of=A and B]{pattern=bricks,pattern color=black!50}
\draw[name path=C,dashed] (-5.8,-1) .. controls (-2,3.7) and (2,3.7) .. (5.8,-1);
\tikzfillbetween[of=B and C]{fill=red!50}
\draw[name path=D] (-5.5,-1) .. controls (-2,3.5) and (2,3.5) .. (5.5,-1);
\tikzfillbetween[of=C and D]{yellow=red!50}
\draw[name path=E] (-5,-1) .. controls (-2,3) and (2,3) .. (5,-1);

\tikzfillbetween[of=D and E]{pattern=crosshatch dots gray}
\draw [name path=F](-4,-1) .. controls (-2,2) and (2,2) .. (4,-1);
\path[name path=line1,yshift=1.5cm] (-3,0) -- +(7,0);%line 1
\path[name path=line2,yshift=1.3cm] (-3,0) -- +(7,0); %line 2
\path [name intersections={of=E and line1 ,by={A1,B1}}];
\path [name intersections={of=E and line2 ,by={A2,B2}}];
\draw[name path=rect](A1)--(B1)--(B2)--(A2)--cycle;
\end{tikzpicture}
\end{document}

答案1

这里有一个使用层的建议。如果pre main定义了层,所有\tikzfillbetween内容都会自动转到该层。

在此处输入图片描述

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{patterns,positioning}
\pgfplotsset{compat=1.10}
\usepgfplotslibrary{fillbetween}

\begin{document}
\begin{tikzpicture}[
  thick,
  pathE/.style={% path E is used twice in the following code
    insert path={(-5,-1) .. controls (-2,3) and (2,3) .. (5,-1)}
  }
]

\pgfdeclarelayer{pre main}
\pgfsetlayers{pre main,main}

\draw[name path=A] (-7.5,-1) .. controls (-3,5.5) and (3,5.5) .. (7.5,-1);
\draw [name path=B](-6,-1) .. controls (-2,4) and (2,4) .. (6,-1);
\draw[name path=C,dashed] (-5.8,-1) .. controls (-2,3.7) and (2,3.7) .. (5.8,-1);
\draw[name path=D] (-5.5,-1) .. controls (-2,3.5) and (2,3.5) .. (5.5,-1);
\draw[name path=E][pathE];

\path[name path=line1,yshift=1.5cm] (-3,0) rectangle +(7,0);%line 1
\path[name path=line2,yshift=1.3cm] (-3,0) -- +(7,0); %line 2
\path[name intersections={of=E and line1 ,by={A1,B1}}];
\path[name intersections={of=E and line2 ,by={A2,B2}}];
\draw[name path=rect](A1)--(B1)--(B2)--(A2)--cycle;
\draw [name path=F](-4,-1) .. controls (-2,2) and (2,2) .. (4,-1);

\tikzfillbetween[of=A and B]{pattern=bricks,pattern color=black!50}
\tikzfillbetween[of=B and C]{red!50}
\tikzfillbetween[of=C and D]{yellow}
\tikzfillbetween[of=D and E]{pattern=crosshatch dots gray}

\pgfonlayer{pre main}
  \begin{scope}
    \clip[pathE];
    \fill[blue!50](A1)rectangle(B1|-current bounding box.north);
    \clip(current bounding box.south west)rectangle(B2-|current bounding box.east);
    \tikzfillbetween[of=E and F]{red!70}
  \end{scope}
\endpgfonlayer

\end{tikzpicture}
\end{document}

相关内容