Pgfplots,将装饰箭头中心放在指定位置

Pgfplots,将装饰箭头中心放在指定位置

我想在参数曲线的垂直部分画一个箭头。例如,请考虑以下摆线。

\documentclass{scrbook}

\usepackage{tikz}
\usepackage{pgfplots}

\usetikzlibrary{
    arrows.meta
  , bending
  , decorations.markings
  }
\pgfplotsset{compat = 1.17}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
        width           = 0.4\textwidth
      , height          = 0.25\textwidth
      , axis equal
      , axis lines      = middle
      , enlargelimits   = false
      , tick style      = {draw = none}
      , ymin            = {0.0}
      , xtick           = \empty
      , ytick           = \empty
      ]
        \addplot+[
            no markers
          , thick
          , domain =  -2.08869:8.37188
          , smooth
          , postaction = {decorate}
          , decoration = {
                markings
              , mark = at position 0.132010 with {\arrow{Stealth[length = 2mm, bend]}}
              , mark = at position 0.210413 with {\arrow{Stealth[length = 2mm, bend]}}
              }
          ] ({x - 1.5 * sin(x r)}, {1.5 - 1.5 * cos(x r)});
    \end{axis}
\end{tikzpicture}

\end{document}

我计算了相应的积分,知道曲线“垂直”部分的位置为 0.132 和 0.210,以总长度的分数表示。结果看起来很难看,因为箭头的尖端就在这里:

在此处输入图片描述

如何将箭头的中心放在这些点上,而不是其尖端?

还有一个附带问题:我指定了“弯曲”,但它看起来根本没有弯曲。为什么?

答案1

由于您明确定义了标记的长度\arrow。您可以使用decoration tranform,请参阅pgfmanual§24.4.1。在本例中,我将箭头移动了一半的长度。

这是输出,其中蓝色表示您的图,筛选后的图用半透明的红色表示。

% arara: lwpdflatex
\documentclass{scrbook}

\usepackage{tikz}
\usepackage{pgfplots}

\usetikzlibrary{
    arrows.meta
  , bending
  , decorations.markings
  }
\pgfplotsset{compat = 1.17}

\begin{document}

\begin{tikzpicture}
    \begin{axis}[
            width           = 0.4\textwidth
            , height          = 0.25\textwidth
            , axis equal
            , axis lines      = middle
            , enlargelimits   = false
            , tick style      = {draw = none}
            , ymin            = {0.0}
            , xtick           = \empty
            , ytick           = \empty
        ]
        \addplot+[
            no markers
            , thick
            , domain =  -2.08869:8.37188
            , smooth
            , trig format=rad
            , postaction = {decorate}
            , decoration = {
                    markings
                    , mark = at position 0.132010 with {\arrow{Stealth[length = 2mm, bend]}}
                    , mark = at position 0.210413 with {\arrow{Stealth[length = 2mm, bend]}}
                }
        ] ({x - 1.5 * sin(x)}, {1.5 - 1.5 * cos(x)});
        \addplot+[
            no markers
            , thick,opacity=0.5
            , domain =  -2.08869:8.37188
            , smooth
            , trig format=rad
            , postaction = {decorate}
            , decoration = {
                    markings
                    , transform={xshift=1mm}
                    , mark = at position 0.132010 with {\arrow{Stealth[length = 2mm, bend]}}
                    , mark = at position 0.210413 with {\arrow{Stealth[length = 2mm, bend]}}
                }
        ] ({x - 1.5 * sin(x)}, {1.5 - 1.5 * cos(x)});
    \end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容