![使用 to[bend=..] 平行移动任意路径,但仅限于两个给定坐标之间](https://linux22.com/image/478072/%E4%BD%BF%E7%94%A8%20to%5Bbend%3D..%5D%20%E5%B9%B3%E8%A1%8C%E7%A7%BB%E5%8A%A8%E4%BB%BB%E6%84%8F%E8%B7%AF%E5%BE%84%EF%BC%8C%E4%BD%86%E4%BB%85%E9%99%90%E4%BA%8E%E4%B8%A4%E4%B8%AA%E7%BB%99%E5%AE%9A%E5%9D%90%E6%A0%87%E4%B9%8B%E9%97%B4.png)
我正在努力改变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}