具有角點意識的 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 留下了評論。我不確定這是否正是打擊樂的初衷。如果是這樣,請告訴我我應該刪除它。

尖角

\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}

帶有 |- 和圓弧的尖角

相關內容