带角落意识的 pgf 路径装饰

带角落意识的 pgf 路径装饰

我尝试创建 pgf 装饰,它将能够在每个段中分辨出它的起点是否是输入路径上的尖角,但我不知道如何做到这一点。

以下面的 MWE 为例。它用曲线装饰路径。当它到达一个角落并且没有空间容纳另一条曲线时,它只会绘制一条简单的线,并在拐角后绘制一条曲线。我怎样才能让它在拐角后绘制另一条简单的线,然后才开始绘制曲线?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations}


\pgfdeclaredecoration{examp}{A}
{   
    \state{A}[width=4mm,auto corner on length=4mm]
    {
        \pgfpathcurveto{\pgfpoint{0mm}{0}}{\pgfpoint{2mm}{5mm}}{\pgfpoint{4mm}{0}};
    }
    %
    \state{final}
    {
    \pgfpathlineto{\pgfpointdecoratedpathlast};
    }
}


\begin{document}
\begin{tikzpicture}

\draw[decoration={examp,path has corners=true},decorate] (0,0) -- (0,3) -- (3,3);

\end{tikzpicture}
\end{document}

答案1

这是你想要的吗?

[我发现当我查看这篇文章时,percusse 留下了一条评论。我不确定这是否正是 percusse 所想的。如果是的话,请告诉我,我应该删除它。]

锐角

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations}
\newlength{\prelength}

\pgfdeclaredecoration{examp}{A}
{
    \state{A}
      [
        width=4mm,
        switch if input segment less than={4mm to B},
      ]
    {
        \pgfpathcurveto{\pgfpoint{0mm}{0}}{\pgfpoint{2mm}{5mm}}{\pgfpoint{4mm}{0}};
    }
    \state{B}
      [
        width=\pgfdecoratedinputsegmentremainingdistance,
        repeat state=0,
        next state=C,
        persistent precomputation={%
          \setlength{\prelength}{\pgfdecoratedinputsegmentremainingdistance}
        },
      ]
    {
      \pgflineto{\pgfpointdecoratedinputsegmentlast};
    }
    \state{C}
      [
        width=\prelength,
        repeat state=0,
        next state=A,
      ]
    {
      \pgflineto{\pgfpoint{\prelength}{0}};
    }
    \state{final}
    {
    \pgfpathlineto{\pgfpointdecoratedpathlast};
    }
}


\begin{document}
\begin{tikzpicture}

\draw[decoration={examp},decorate] (0,0) -- (0,3) -- (3,3) |-  cycle;
\draw[decoration={examp},decorate, xshift=40mm] (0,0) -- (0,3) -- (3,3) arc (90:-90:1.5) [out=135, in=45] to cycle;

\end{tikzpicture}
\end{document}

用 |- 和圆弧形成尖角

相关内容