在 tik z 中将 snake=snake 应用于曲线

在 tik z 中将 snake=snake 应用于曲线

如何使用 tikz 绘制蛇形曲线?我想要的是这样的:

在此处输入图片描述

我尝试使用以下代码来实现这一点:

\documentclass[12pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{snakes}

\begin{figure}[h]
    \begin{center}
        \begin{tikzpicture}[scale=1.5]
            \draw[->] (0,0) -- (4,0) node[below] {$\tilde{X}$};
            \draw[->] (0,0) -- (0,4) node[left] {$\tilde{T}$};
            \draw[red, very thick, snake=snake,->] (0,0) -- (3.5,3.5) node[right,black] {$r=2m$};
            \draw[thick ,<->] (3.5,-3.5) -- (-3.5,3.5) node[left] {$r=2m$};


            \draw[blue,bend right=40,thick, dashed] (1.5,1.5) to (1.5,-1.5);
            \draw[blue,bend right=41,thick, dashed] (2.0,2.0) to (2.0,-2.0);
            \draw[blue,bend right=42,thick, dashed] (2.5,2.5) to (2.5,-2.5);
            \draw[blue,bend right=43,thick, dashed] (3.0,3.0) to (3.0,-3.0);
            \draw[blue,bend right=44,thick, dashed] (3.5,3.5) to (3.5,-3.5);
            \draw[red, snake=snake, very thick] (-3,3) to [out= -45, in = 225](3,3);
            %\draw[purple,bend right=40,very thick] (0,0) to (3,0);
           draw[thick] (0,1.78) node[above] {$r=0 $}; 


        \end{tikzpicture}
    \end{center}
\end{figure}

我尝试“蛇形”红色曲线的部分是:

\draw[red, snake=snake, very thick] (-3,3) to [out= -45, in = 225](3,3);

但我得到的是这样的:

在此处输入图片描述

snake = snake 命令适用于直线,但为什么它不适用于曲线?我该如何解决这个问题?

答案1

这个snake=snake选项很奇怪(我不想知道它为什么能工作)。官方语法是decoration,decorate=snake(参见第 55 页,pgfmanual,v3.0.1a)。

在此处输入图片描述

\documentclass[margin=2mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{snakes}
\begin{document}
\begin{tikzpicture}[scale=1.5]
  \draw[->] (0,0) -- (4,0) node[below] {$\tilde{X}$};
  \draw[->] (0,0) -- (0,4) node[left] {$\tilde{T}$};
  \draw[red, very thick,->,decorate] (0,0) -- (3.5,3.5) node[right,black] {$r=2m$};
  \draw[thick ,<->] (3.5,-3.5) -- (-3.5,3.5) node[left] {$r=2m$};


  \draw[blue,bend right=40,thick, dashed] (1.5,1.5) to (1.5,-1.5);
  \draw[blue,bend right=41,thick, dashed] (2.0,2.0) to (2.0,-2.0);
  \draw[blue,bend right=42,thick, dashed] (2.5,2.5) to (2.5,-2.5);
  \draw[blue,bend right=43,thick, dashed] (3.0,3.0) to (3.0,-3.0);
  \draw[blue,bend right=44,thick, dashed] (3.5,3.5) to (3.5,-3.5);
  \draw[red,decorate,decoration=snake, very thick] (-2.9,3.1) to [out= -45, in = 225](2.9,3.1);
\end{tikzpicture}
\end{document}

相关内容