通过交叉方法填充线段:没有命名路径称为

通过交叉方法填充线段:没有命名路径称为

我只是想填充绘图的每个外围部分。六边形和圆形的名称分别为testcirc。此外,连接六边形边缘和外圆的线段在 for 循环中命名。但是,当我使用名称作为交叉线段时,there is no named path called '2 and circ and test'会抛出 a。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,shapes,positioning}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
    \begin{tikzpicture}
    \node[
    fill=red!15,
    draw = black,
    regular polygon,
    regular polygon sides=6,
    align=center,
    minimum size=5cm](test){};

    \node[
    fill=none,
    draw = black,
    circle,
    dashed,
    minimum size=9.2cm](circ){};

    \foreach \n in {1,...,6}
    {
        \draw[black, name path = \n](test.corner \n) --
        ({\n*60}:4.6);
    }

    \node[] (c) at (test.center){$\pi^{0}$};

    \foreach \n in {1,...,6}
    {
        \node[] (\n) at ({\n*60+30}:3.3){$\pi^{\n}$};
    }

    \fill[
    orange!50,
    intersection segments={
        of=1 and 2 and circ and test
    }];
    \end{tikzpicture}
\end{document}

我究竟做错了什么?

答案1

在这个例子中,最简单的可能性是

\fill[orange] (test.corner 1) -- (60:4.6) arc(60:120:4.6) -- (test.corner 2);

但是,我们来讨论一下如何构建两条以上路径的交叉段。只需从两条路径的交叉段定义一条新路径,将其存储为辅助路径,然后将其与下一条路径组合,依此类推。

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,shapes,positioning,backgrounds}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{fillbetween}
\begin{document}
    \begin{tikzpicture}
    \node[name path=test,
    fill=red!15,
    draw = black,
    regular polygon,
    regular polygon sides=6,
    align=center,
    minimum size=5cm](test){};

    \node[name path=circ,
    fill=none,
    draw = black,
    circle,
    dashed,
    minimum size=9.2cm](circ){};

    \foreach \n in {1,...,6}
    {
        \draw[black, name path = \n](test.corner \n) --
        ({\n*60}:4.6);
    }

    \node (c) at (test.center){$\pi^{0}$};

    \foreach \n in {1,...,6}
    {
        \node[] (\n) at ({\n*60+30}:3.3){$\pi^{\n}$};
    }
    \path [name path=aux1,%draw=blue,thick,->,
    intersection segments={of=1 and circ,
        sequence={L1--R2}}];
    \begin{scope}[on background layer]
      %\fill[orange] (test.corner 1) -- (60:4.6) arc(60:120:4.6) -- (test.corner 2);
      \path [fill=orange,%draw=red,thick,->,
      intersection segments={of=aux1 and 2,
          sequence={L1--R1[reverse]}}];
    \end{scope} 
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容