Tikz:合并点处封闭物体上的丑陋装饰

Tikz:合并点处封闭物体上的丑陋装饰

当我在封闭的对象上使用装饰时,合并点通常很难看。即使有选项,箭头也会出现同样的问题pre:有时之字形会“靠近”箭头符号停止,有时则会远离箭头符号停止。

有什么想法可以纠正这个问题吗?我知道对于固定的段长度,没有真正的解决方案,但我想如果我们允许段长度稍微移动一点,那么我们就可以找到精确的段长度以获得一个好的合并点。

在此处输入图片描述

梅威瑟:

\documentclass[beamer,tikz,preview]{standalone}
\usetikzlibrary{positioning,decorations.pathreplacing,decorations.pathmorphing,shapes.geometric}
\begin{document}
\begin{standaloneframe}
  \begin{tikzpicture}[main style/.style={
        ellipse,draw,fill=blue!30,decorate,
        decoration={zigzag,segment length=1.1mm,amplitude=.5mm}
      }]
    % Ok
    \node[main style] at (0,0) {ABC};
  \end{tikzpicture}
\end{standaloneframe}
\end{document}

-- 编辑 -- 在 marmot 的建议下,我尝试了新complete sines版本,看看蛇形装饰是否会看起来更漂亮,但绘图看起来也有点奇怪,尤其是在东/西部分。但请注意,“关节”看起来更好,并且对于锯齿形样式来说可能已经足够了。

在此处输入图片描述

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations,shapes.geometric,decorations.pathreplacing,decorations.pathmorphing}
\begin{document}

\pgfdeclaredecoration{complete sines}{initial}
{
    \state{initial}[
        width=+0pt,
        next state=sine,
        persistent precomputation={\pgfmathsetmacro\matchinglength{
            \pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
            \setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
        }] {}
    \state{sine}[width=\pgfdecorationsegmentlength]{
        \pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
        \pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
        \pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
        \pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
}
    \state{final}{}
}

\begin{tikzpicture}[
    every node/.style={
        decoration={
          complete sines,
          % zigzag,
            segment length=1mm,
            amplitude=1mm
        },
        decorate
    }]
\node[ellipse,draw]{Hello};
\end{tikzpicture}
\end{document}

答案1

这是一个版本complete zigzag而不是杰克的complete sines,本答案即以此为基础。编辑:添加了用于闭式循环的特殊曲折。第二次编辑:特殊的锯齿形,在增加曲率时效果可能会更好。标准锯齿形的“问题”在于锯齿形的峰值在切线空间中发生了偏移。另一方面,在“tobias zigzag”装饰中,它位于切线空间中原点的正上方(或正下方)。

在此处输入图片描述

平均能量损失

\documentclass[beamer,tikz,preview]{standalone}
\usetikzlibrary{positioning,decorations.pathreplacing,decorations.pathmorphing,shapes.geometric}
% https://tex.stackexchange.com/a/25689/121799
\pgfdeclaredecoration{complete sines}{initial}
{
    \state{initial}[
        width=+0pt,
        next state=sine,
        persistent precomputation={\pgfmathsetmacro\matchinglength{
            \pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
            \setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
        }] {}
    \state{sine}[width=\pgfdecorationsegmentlength]{
        \pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
        \pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
        \pgfpathsine{\pgfpoint{0.25\pgfdecorationsegmentlength}{-0.5\pgfdecorationsegmentamplitude}}
        \pgfpathcosine{\pgfpoint{0.25\pgfdecorationsegmentlength}{0.5\pgfdecorationsegmentamplitude}}
}
    \state{final}{}
}

\pgfdeclaredecoration{complete zigzag}{initial}{
\state{initial}[
        width=+0pt,
        next state=half up,
        persistent precomputation={\pgfmathsetmacro\matchinglength{
            \pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
            \setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
        }] {}
  \state{half up}[
        width=+.25\pgfdecorationsegmentlength,
        next state=big down]
        {\pgfpathlineto{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
    }
  \state{big down}[switch if less than=+.5\pgfdecorationsegmentlength to center finish,
                   width=+.5\pgfdecorationsegmentlength,
                   next state=big up]
  {
    \pgfpathlineto{\pgfqpoint{.5\pgfdecorationsegmentlength}{-\pgfdecorationsegmentamplitude}}
  }
  \state{big up}[switch if less than=+.5\pgfdecorationsegmentlength to center finish,
                 width=+.5\pgfdecorationsegmentlength,
                 next state=big down]
  {
    \pgfpathlineto{\pgfqpoint{.5\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
  }
  \state{center finish}[width=0pt, next state=final]{
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointdecoratedpathlast}
  }
}

\pgfdeclaredecoration{zigzag cycle}{initial}{
\state{initial}[
        width=+0pt,
        next state=half up,
        persistent precomputation={\pgfmathsetmacro\matchinglength{
            \pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
            \setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
        }] {}
  \state{half up}[
        width=+.25\pgfdecorationsegmentlength,
        next state=big down]
        {\pgfcoordinate{zigzag-cycle-start}{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
        \pgfpathmoveto{\pgfqpoint{.25\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
    }
  \state{big down}[switch if less than=+.5\pgfdecorationsegmentlength to center finish,
                   width=+.5\pgfdecorationsegmentlength,
                   next state=big up]
  {
    \pgfpathlineto{\pgfqpoint{.5\pgfdecorationsegmentlength}{-\pgfdecorationsegmentamplitude}}
  }
  \state{big up}[switch if less than=+.5\pgfdecorationsegmentlength to center finish,
                 width=+.5\pgfdecorationsegmentlength,
                 next state=big down]
  {
    \pgfpathlineto{\pgfqpoint{.5\pgfdecorationsegmentlength}{\pgfdecorationsegmentamplitude}}
  }
  \state{center finish}[width=0pt, next state=final]{
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointanchor{zigzag-cycle-start}{center}}
  }
}

\pgfdeclaredecoration{tobias zigzag cycle}{initial}{
\state{initial}[
        width=+0pt,
        next state=big down,
        persistent precomputation={
            \pgfmathsetmacro{\myint}{int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
            \ifodd\myint
             \pgfmathsetmacro\matchinglength{
             \pgfdecoratedinputsegmentlength / int(1+\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
            \else
             \pgfmathsetmacro\matchinglength{
             \pgfdecoratedinputsegmentlength / int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
            \fi
            \setlength{\pgfdecorationsegmentlength}{\matchinglength pt}
            \pgfmathsetmacro{\myint}{int(\pgfdecoratedinputsegmentlength/\pgfdecorationsegmentlength)}
        }] {
        \pgfcoordinate{zigzag-cycle-start}{\pgfqpoint{0pt}{-\pgfdecorationsegmentamplitude}}
        \pgfpathmoveto{\pgfqpoint{0pt}{-\pgfdecorationsegmentamplitude}}
        }
  \state{big down}[switch if less than=+.5\pgfdecorationsegmentlength to center finish,
                   width=+.5\pgfdecorationsegmentlength,
                   next state=big up]
  {
    \pgfpathlineto{\pgfqpoint{0pt}{-\pgfdecorationsegmentamplitude}}
  }
  \state{big up}[switch if less than=+.5\pgfdecorationsegmentlength to center finish,
                 width=+.5\pgfdecorationsegmentlength,
                 next state=big down]
  {
    \pgfpathlineto{\pgfqpoint{0pt}{\pgfdecorationsegmentamplitude}}
  }
  \state{center finish}[width=0pt, next state=final]{
   % this state is unecessary at the moment
  }
  \state{final}
  {
    \pgfpathlineto{\pgfpointanchor{zigzag-cycle-start}{center}}
  }
}

\begin{document}
\begin{standaloneframe}
  \begin{tikzpicture}[main style/.style={
        ellipse,draw,fill=blue!30,decorate,
        decoration={zigzag,segment length=1.1mm,amplitude=.5mm}
      },
      complete main style/.style={
        ellipse,draw,fill=blue!30,decorate,
        decoration={complete zigzag,segment length=1.1mm,amplitude=.5mm}
      },
      cyclic main style/.style={
        ellipse,draw,fill=blue!30,decorate,
        decoration={zigzag cycle,segment length=1.1mm,amplitude=.5mm}
      },
      cyclic tobias style/.style={
        ellipse,draw,fill=blue!30,decorate,
        decoration={tobias zigzag cycle,segment length=1.1mm,amplitude=.5mm}
      }]

    \node[main style] at (0,0) {ABC};
    \node[main style] at (5,0) {normal zigzag};

    \node[complete main style] at (0,-1) {ABC};
    \node[complete main style] at (5,-1) {complete zigzag};

    \node[cyclic main style] at (0,-2) {ABC};
    \node[cyclic main style] at (5,-2) {zigzag cycle};

    \node[cyclic tobias style] at (0,-3) {ABC};
    \node[cyclic tobias style] at (5,-3) {tobias zigzag};
  \end{tikzpicture}

  \begin{tikzpicture}[font=\sffamily]
   \draw (0,0) arc(135:45:{2*sqrt(2)}) coordinate[midway](X);
   \draw[blue] ([xshift=-2cm]X) -- ++(4,0) node[right]{tangent};
   \draw[red] (X) -- ++ (0.6,1) node[right]{standard}-- ++ (0.6,-1);
   \draw[green!60!black] ([xshift=-0.6cm]X) -- ++ (0.6,1) node[left]{tobias} -- ++ (0.6,-1);
  \end{tikzpicture}
\end{standaloneframe}
\end{document}

在此处输入图片描述

相关内容