PGF 图抽样弄乱箭头

PGF 图抽样弄乱箭头

使用 pgf 创建某些图时,采样会使某些函数(例如平方根函数)的箭头尖端混乱。我将采样增加到 100 以使函数看起来更好,但末尾的箭头却变得混乱。这个话题之前已经提出过这里但我找不到解决此问题的答案。

\documentclass{article}
\usepackage{tikz}

\begin{document}
\usetikzlibrary{arrows.meta ,shapes,angles, decorations.pathmorphing}

\begin{tikzpicture}
\draw[line width=0.5pt, -{Latex[length=6pt,width=4pt]}] (-3.5,0)--(3.5,0)node[above, xshift=-0.12cm]{$x$};
\draw[line width=0.5pt, -{Latex[length=6pt,width=4pt]}] (0,-3.5)--(0,3.5)node[right, yshift=-0.15cm]{$y$};

\draw[xscale=1, yscale=1, line width=1pt, domain=-3.5:-0.6,
smooth,variable=\x,latex-latex,samples=200] plot ({\x},{(-2/\x)});
\draw[xscale=1, yscale=1, line width=1pt, domain=0.6:3.5,
smooth,variable=\x,latex-latex,samples=200] plot ({\x},{(-2/\x)});

\foreach \x/\y in {-1/2} {
    \fill (\x,\y) circle (3pt);
    \node[above left] at (\x,\y) {$(\x,\y)$};
}
\end{tikzpicture} 
\end{document}

在此处输入图片描述

答案1

如果不作弊,这是不可能做到的。plot绘制许多小线段(或使用smooth选项绘制许多小曲线)。当应用箭头尖端时,曲线会缩短,以不显示尖端下的曲线。缩短仅适用于第一个(或最后一个)线段(或曲线),因此当它太短时会失败。

摘自有关箭头的手册第 192 页:

TikZ 将通过缩短第一段来修改路径,而缩短低于其长度的段可能会导致奇怪的效果。


作弊的解决方案可能是用白色的东西覆盖线条(如果背景不是白色或单色,解决方案会变得有点复杂),然后再像这样画箭头:

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw[ultra thick, {Circle[white]}-{Circle[white]}, postaction={Latex-Latex, tips}] plot[domain=0.6:3.5, samples=200] ({\x},{(-2/\x)});
\end{tikzpicture} 
\end{document}

带箭头的曲线


彩色版本,显示正在发生的事情

\documentclass[tikz, border=1cm]{standalone}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
\draw[ultra thick, {Circle[blue]}-{Circle[blue]}, postaction={{Latex[teal]}-{Latex[teal]}, tips}] plot [domain=0.6:3.5, samples=200] ({\x},{(-2/\x)});
\draw[red] plot[domain=0.6:3.5, samples=200] ({\x},{(-2/\x)});
\end{tikzpicture} 
\end{document}

带圆圈和尖箭头的曲线

相关内容