使用 to[bend=..] 平行移动任意路径,但仅限于两个给定坐标之间

使用 to[bend=..] 平行移动任意路径,但仅限于两个给定坐标之间

我正在努力改变TikZ:仅绘制给定路径的某个中心长度满足我的需求。我有一条路径,\draw (A) to [bend right=30] (B); 现在我想以平行的方式移动这条路径,但只显示其中的一部分。我希望可以用两个不同的坐标任意选择这个片段。这是我的代码:

\documentclass[12pt, thmsa]{article}
\usepackage{tikz,pgf,  pgfplots}
\pgfdeclaredecoration{ignore}{final}
{
\state{final}{}
}

% Declare the actual decoration.
\pgfdeclaremetadecoration{myshortershift}{initial}{
  \state{initial}[
  width=1pt,
        next state=myshortershift
    ]
    {\decoration{moveto}}

    \state{myshortershift}[
        width={\the\pgfdecorationsegmentlength},
        next state=final
    ]
    {\decoration{curveto}}

    \state{final}
    {\decoration{ignore}}
  }
  \tikzset{myshortershift segment/.style={decoration={myshortershift},decorate, segment length=#1}}

\begin{document}
 \begin{tikzpicture}[>=latex]
  \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    xmin=0, xmax=10, 
    ymin=0, ymax=10,
     x label style={at={(axis description cs:1,-.01)},anchor=south},
    ylabel style={at={(axis description cs:0.1,1)},anchor=west, rotate=270}, 
    xlabel={$X$},
    ylabel={$Y$},
    ytick=\empty,
    xtick=\empty,
    ]
    \coordinate (A) at (axis cs:2.2, 9.5);
    \coordinate (B) at (axis cs:8, .5);
    \draw (A) to [bend right=30] (B);
 \draw[blue] (axis cs:2.2+1, 9.5+1) to [bend right=30]  (axis cs:8+1,.5+1);
    \draw [blue,->, dotted, myshortershift segment=1.75cm] (axis cs:2.2+.5,9.5+.5) to [bend right=30]  (axis cs:8+.5,.5+.5);
    \draw [blue,->, dotted, myshortershift segment=1.75cm] (axis cs:8+.5,.5+.5) to [bend left=30]  (axis cs:2.2+.5,9.5+.5);
  \end{axis}
  \end{tikzpicture} 
\end{document}

在此处输入图片描述

我试图让虚线箭头在任意两个给定的坐标处开始和停止(这些将从一些交叉点命令中得出)

谢谢

答案1

欢迎使用 TeX-SE!它定义了一条移位曲线,并用两条线(细红线引导视线)绘制了相关的交叉段。它还绘制了两个交叉点之间的线段。为此,必须首先定义一条辅助路径(称为rest1),该路径从第一个交叉点开始,一直到曲线的末端。然后用第二条线绘制该路径的第一个交叉段。还请注意,在最近版本的 pgfplots 中,您可以使用 访问\pgfplotsset{compat=...},但axis cs:不再需要它。)

\documentclass[12pt, thmsa]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\pgfdeclaredecoration{ignore}{final}
{
\state{final}{}
}

% Declare the actual decoration.
\pgfdeclaremetadecoration{myshortershift}{initial}{
  \state{initial}[
  width=1pt,
        next state=myshortershift
    ]
    {\decoration{moveto}}

    \state{myshortershift}[
        width={\the\pgfdecorationsegmentlength},
        next state=final
    ]
    {\decoration{curveto}}

    \state{final}
    {\decoration{ignore}}
  }
  \tikzset{myshortershift segment/.style={decoration={myshortershift},decorate, segment length=#1}}

\begin{document}


 \begin{tikzpicture}[>=latex]
  \begin{axis}[
    axis x line=bottom,
    axis y line=left,
    xmin=0, xmax=10, 
    ymin=0, ymax=10,
     x label style={at={(axis description cs:1,-.01)},anchor=south},
    ylabel style={at={(axis description cs:0.1,1)},anchor=west, rotate=270}, 
    xlabel={$X$},
    ylabel={$Y$},
    ytick=\empty,
    xtick=\empty,
    ]
    \coordinate (A) at (2.2, 9.5);
    \coordinate (B) at (8, .5);
    \draw (A) to [bend right=30] (B);
    \draw[blue] (2.2+1, 9.5+1) to [bend right=30]  (8+1,.5+1);
    \path[%draw=blue!30,ultra thin,
     name path=shifted curve] (2.2+2, 9.5+2) to [bend right=30]  (8+2,.5+2);
    \path[draw=red!30,ultra thin,name path=line1] (2.2,8) -- (10,8);
    \path[draw=red!30,ultra thin,name path=line2] (2.2,4) -- (10,4);
    \draw[-latex,blue,very thick,
        intersection segments={of=shifted curve and line1,sequence={A0}}];
    \draw[-latex,blue,very thick,
        intersection segments={of=shifted curve and line2,sequence={A1[reverse]}}];
    \path[name path=rest1,intersection segments={of=shifted curve and line1,sequence={A1}}];    
    \draw[latex-latex,red,very thick,
        intersection segments={of=rest1 and line2,sequence={A0}}];
%     \draw [blue,->, dotted, myshortershift segment=1.75cm] (axis cs:2.2+.5,9.5+.5) to [bend right=30]  (axis cs:8+.5,.5+.5);
%     \draw [blue,->, dotted, myshortershift segment=1.75cm] (axis cs:8+.5,.5+.5) to [bend left=30]  (axis cs:2.2+.5,9.5+.5);
  \end{axis}
  \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容