波浪图和其他图形元素之间奇怪的不一致

波浪图和其他图形元素之间奇怪的不一致

我尝试制作一些顶部带有箭头的波浪图。令我惊讶的是,箭头实际上并没有出现在顶部,而是略微低于顶部。我甚至不知道为什么会发生这种情况。明确强制箭头从波浪顶部开始。我该如何解决这个问题? 在此处输入图片描述

我希望我能以优雅的方式重新调整语句中的箭头\newcommand。提前感谢您的帮助。

\documentclass{article}

% First command that computes the hight of a single wave on position x.
\newcommand{\wave}[3]{
    #2*#2 / (cosh(#2*(#1 - #3) + ln(#2))*cosh(#2*(#1 - #3) + ln(#2)))
}

% Command to draw a single wave, with its arrow (supposed to be on top),
\newcommand{\drawwave}[2]{
    \fill [samples = 200, color=blue, domain={#1 - 7/#2}:{#1 + 7/#2}]
        plot(\x, \wave{\x}{#2}{#1});
    \draw[->, color=green](#1,{\wave{#1}{#2}{#1}}) -- (#1 + 5*#2,{\wave{#1}{#2}{#1}});
}

%the four necessary packages
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{graphicx}
    \usetikzlibrary{calc}

\usepackage[dutch]{babel}
    \selectlanguage{dutch}

\begin{document}

    % Drawing four waves.
    \begin{figure}
    \begin{tikzpicture}[xscale=0.2]
        \draw [color = blue](0,0) -- (60,0);
        \drawwave{10}{0.5};
        \drawwave{25}{1.5};
        \drawwave{45}{1};
        \drawwave{35}{2}
    \end{tikzpicture}
    \end{figure}

\end{document}

值得注意的是,只有当第二个参数等于时2,箭头才真正从波浪的顶部开始。

答案1

首先,{\wave{\x}{#2}{#1}}的扩展与 不同\wave{\x}{#2}{#1}。其次,从修正图中可以看出, 峰值并不出现在 处\x=#1

\documentclass{standalone}

% First command that computes the hight of a single wave on position x.
\newcommand{\wave}[3]{
    #2*#2 / (cosh(#2*(#1 - #3) + ln(#2))*cosh(#2*(#1 - #3) + ln(#2)))
}

% Command to draw a single wave, with its arrow (supposed to be on top),
\newcommand{\drawwave}[2]{
    \fill [samples = 200, color=blue, domain={#1 - 4/#2}:{#1 + 4/#2}]
        plot(\x, {\wave{\x}{#2}{#1}});
    \draw[->, color=green] (#1,{\wave{#1}{#2}{#1}}) -- (#1 + 5*#2,{\wave{#1}{#2}{#1}});
}

%the four necessary packages
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{graphicx}
    \usetikzlibrary{calc}

\begin{document}

    % Drawing four waves.
    \begin{tikzpicture}[xscale=0.2]
        \draw [color = blue](0,0) -- (60,0);
        \drawwave{10}{0.5};
        \drawwave{25}{1.5};
        \drawwave{45}{1};
        \drawwave{35}{2}
    \end{tikzpicture}

\end{document}

演示

相关内容