如何填充多条路径之间的区域

如何填充多条路径之间的区域

我有以下 tikz 代码,其中多条路径相互交叉。我努力寻找一种方法来填充结果图片的六个不同区域,每个区域都使用不同的图案(不一定是纯色)。

\documentclass{article}

\usepackage{tikz} %used for theorem style
\usetikzlibrary{positioning}
\usetikzlibrary{hobby}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}
\coordinate (upleft) at (0,0);
\coordinate[right = 12cm of upleft] (upright);
\coordinate[below = 14cm of upright] (downright);
\coordinate[below = 14cm of upleft] (downleft);

\draw[name path=UP] (upleft) -- (upright);
\draw[name path=RIGHT] (upright) -- (downright);
\draw[name path=DOWN] (downright) -- (downleft);
\draw[name path=LEFT] (downleft) -- (upleft);

\coordinate[above right = 8cm and 6cm of downleft] (halt);
\coordinate[right = 2.5cm of upleft] (coneupleft);
\coordinate[left = 2.5cm of upright] (coneupright);
\coordinate[right = 4cm of downleft] (conedownleft);
\coordinate[left = 4cm of downright] (conedownright);

%left to right Curve
\coordinate[below = 2cm of upleft] (curve1left);
\coordinate[below = 2cm of upright] (curve1right);
\coordinate[below = 4cm of halt] (curve1middle);
\coordinate[left = 3cm of halt] (curve1middle1);
\coordinate[right = 3cm of halt] (curve1middle2);
\draw[name path=HIGH] (curve1left) to [curve through = {(curve1middle1) (curve1middle) (curve1middle2)}] (curve1right);

%up to bottom curves
\coordinate[right = 1cm of upleft] (vcurve1upl);
\coordinate[left = 1cm of upright] (vcurve1upr);
\coordinate[left = 3cm of conedownleft] (vcurve1bottoml);
\coordinate[right = 3cm of conedownright] (vcurve1bottomr);
\coordinate[left = 3.5cm of halt] (vcurve1ml);
\coordinate[right = 3.5cm of halt] (vcurve1mr);
\draw[name path=DNCLEFT] (vcurve1upl) to [curve through = {(vcurve1ml)}] (vcurve1bottoml);
\draw[name path=DNCRIGHT] (vcurve1upr) to [curve through = {(vcurve1mr)}] (vcurve1bottomr);

\end{tikzpicture}

\end{document}

结果如下:

在此处输入图片描述

目标是用不同的模式填充六个区域,如果可能的话,不触及现有代码,而只添加新的代码行。

从我看到的各种类似的问题来看,可能存在如下代码组合的可能性:

\fill[orange, intersection segments={
                of=HIGH and DNCLEFT,
                sequence={L2--R2}
              }];

但是上面的代码是用来填充两个路径之间的模式的,而不是更多。另外,我不理解L2and的含义R2(显然也可以从R0toR2L0to开始L2,并与某些reverse关键字一起使用),所以我很难将它们混合在一起来实现我想要的效果。

请注意,我正在处理的完整图片比我在此处提供的区域要多得多,这只是一个最小的例子。

理想情况下,一些剪辑命令的组合形式为“将所有内容剪辑到左侧/右侧/顶部/底部给定路径*”会很棒,但我找不到如何做到这一点。

答案1

您可以将交叉段组合成一条新路径,然后将其用于fillbetween另一条路径,依此类推。但在这里,简单的剪辑可能更容易处理。您可以使用键insert path来避免不必要的重复。intersections这里不需要,但我保留了所有name path键。

\documentclass{article}

\usepackage{tikz} %used for theorem style
\usetikzlibrary{positioning}
\usetikzlibrary{hobby}
\usetikzlibrary{intersections}
\usetikzlibrary{backgrounds}
\begin{document}

\begin{tikzpicture}
\coordinate (upleft) at (0,0);
\coordinate[right = 12cm of upleft] (upright);
\coordinate[below = 14cm of upright] (downright);
\coordinate[below = 14cm of upleft] (downleft);

\draw[name path=UP] (upleft) -- (upright);
\draw[name path=RIGHT] (upright) -- (downright);
\draw[name path=DOWN] (downright) -- (downleft);
\draw[name path=LEFT] (downleft) -- (upleft);

\coordinate[above right = 8cm and 6cm of downleft] (halt);
\coordinate[right = 2.5cm of upleft] (coneupleft);
\coordinate[left = 2.5cm of upright] (coneupright);
\coordinate[right = 4cm of downleft] (conedownleft);
\coordinate[left = 4cm of downright] (conedownright);

%left to right Curve
\coordinate[below = 2cm of upleft] (curve1left);
\coordinate[below = 2cm of upright] (curve1right);
\coordinate[below = 4cm of halt] (curve1middle);
\coordinate[left = 3cm of halt] (curve1middle1);
\coordinate[right = 3cm of halt] (curve1middle2);
\tikzset{HIGH/.style={insert path={(curve1left) to [curve through = {(curve1middle1) (curve1middle) (curve1middle2)}] (curve1right)}}}
\draw[name path=HIGH,HIGH] ;

%up to bottom curves
\coordinate[right = 1cm of upleft] (vcurve1upl);
\coordinate[left = 1cm of upright] (vcurve1upr);
\coordinate[left = 3cm of conedownleft] (vcurve1bottoml);
\coordinate[right = 3cm of conedownright] (vcurve1bottomr);
\coordinate[left = 3.5cm of halt] (vcurve1ml);
\coordinate[right = 3.5cm of halt] (vcurve1mr);
\tikzset{DNCLEFT/.style={insert path={(vcurve1upl) to [curve through = {(vcurve1ml)}] (vcurve1bottoml)}},
DNCRIGHT/.style={insert path={(vcurve1upr) to [curve through = {(vcurve1mr)}] (vcurve1bottomr)}}}
\draw[name path=DNCLEFT,DNCLEFT] ;
\draw[name path=DNCRIGHT,DNCRIGHT];
\begin{scope}[on background layer]
 \begin{scope}
  \fill[orange,HIGH] -- (upright) -- (upleft) -| cycle;
 \end{scope}
 %
 \begin{scope}
  \fill[cyan,HIGH] -- (downright) -- (downleft) -| cycle;
 \end{scope}
 %
 \begin{scope}
  \clip[DNCLEFT] -- (downleft)  |- (upleft) -| cycle;
  \fill[red,HIGH] --  (upright) -- (upleft) -- cycle;
 \end{scope}
 %
 \begin{scope}
  \clip[DNCRIGHT] -- (downright)  -- (upright) -| cycle;
  \fill[blue,HIGH] -- (upright) -| cycle;
 \end{scope}
 %
 \begin{scope}
  \clip[DNCLEFT] -- (downleft)  |- (upleft) -| cycle;
  \fill[magenta,HIGH] -- (downright) -- (downleft) -| cycle;
 \end{scope}
 %
 \begin{scope}
  \clip[DNCRIGHT] -- (downright)  -- (upright) -| cycle;
  \fill[purple,HIGH] -- (downright) -- (downleft) -| cycle;
 \end{scope}
\end{scope}
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容