TikZ - pgfdeclaredecoration 与曲线路径

TikZ - pgfdeclaredecoration 与曲线路径

我想使用复杂的装饰,然后将其应用于弯曲的路径。但 TikZ 似乎不会弯曲单个段。您知道如何才能获得所需的行为吗?

是否有办法添加路径,类似于 pgfplots 中的堆叠图?

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

\pgfdeclaredecoration{reserve}{initial}
{
  \state{initial}[width=\pgfdecoratedpathlength]
  {
    \pgfpathlineto{\pgfpoint{0pt}{-4pt}}
    \pgfpathlineto{\pgfpoint{0.15*\pgfdecoratedpathlength}{7pt}}
    \pgfpathlineto{\pgfpoint{0.2*\pgfdecoratedpathlength}{-7pt}}
    \pgfpathlineto{\pgfpoint{0.35*\pgfdecoratedpathlength}{5pt}}
    \pgfpathlineto{\pgfpoint{0.4*\pgfdecoratedpathlength}{-5pt}}
    \pgfpathcurveto{\pgfpoint{0.5*\pgfdecoratedpathlength}{3pt}}{\pgfpoint{0.6*\pgfdecoratedpathlength}{-3pt}}{\pgfpoint{0.6*\pgfdecoratedpathlength}{-3pt}}
    \pgfpathlineto{\pgfpoint{0.65*\pgfdecoratedpathlength}{6pt}}
    \pgfpathlineto{\pgfpoint{0.82*\pgfdecoratedpathlength}{-7pt}}
    \pgfpathlineto{\pgfpoint{0.9*\pgfdecoratedpathlength}{7pt}}
    \pgfpathlineto{\pgfpoint{0.97*\pgfdecoratedpathlength}{-2pt}}
    \pgfpathlineto{\pgfpoint{\pgfdecoratedpathlength}{0pt}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointdecoratedpathlast}
  }
}

\begin{document}
\begin{tikzpicture}
  \draw[black, decorate, decoration={name=reserve}, very thick] (0,5) -- (5, 5) ;
  \draw[black, decorate, decoration={name=reserve}, very thick] (0,0) to[bend left] (5, 0) ;
\end{tikzpicture}
\end{document}

直线和曲线的装饰

答案1

装饰的工作原理是将事物分成小部分,然后将它们单独地安装到路径上。但是,我无法使用 \pgfdecoratedpathlength 使其工作。

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

\pgfdeclaredecoration{reserve}{initial}
{
  \state{initial}[width=1cm,next state=break1]
  {
    \pgfpathlineto{\pgfpoint{0pt}{-4pt}}
    \pgfpathlineto{\pgfpoint{0.75cm}{7pt}}
    \pgfpathlineto{\pgfpoint{1cm}{-7pt}}
  }
  \state{break1}[width=1cm,next state=break2]
  {
    \pgfpathlineto{\pgfpoint{.75cm}{5pt}}
    \pgfpathlineto{\pgfpoint{1cm}{-5pt}}
  }
  \state{break2}[width=1cm,next state=break3]
  {
    \pgfpathcurveto{\pgfpoint{.5cm}{3pt}}{\pgfpoint{1cm}{-3pt}}{\pgfpoint{1cm}{-3pt}}%
  }
  \state{break3}[width=1cm,next state=break4]
  {
    \pgfpathlineto{\pgfpoint{.25cm}{6pt}}
    \pgfpathlineto{\pgfpoint{1cm}{-7pt}}
  }
  \state{break4}[width=1cm]
  {
    \pgfpathlineto{\pgfpoint{.5cm}{7pt}}
    \pgfpathlineto{\pgfpoint{.9cm}{-2pt}}
    \pgfpathlineto{\pgfpoint{1cm}{0pt}}
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointdecoratedpathlast}
  }
}

\begin{document}
\begin{tikzpicture}
  \draw[black, decorate, decoration={name=reserve}, very thick] (0,5) -- (5cm,5) ;
  \draw[black, decorate, decoration={name=reserve}, very thick] (0,0) to[bend left] (5, 0) ;
\end{tikzpicture}
\end{document}

装饰

相关内容