如何在两条曲线上的节点之间画直线?

如何在两条曲线上的节点之间画直线?

本质上,我认为我的问题在于尝试指定沿 x 轴一定距离的节点。我理想情况下希望在两条曲线上的两个节点之间绘制一条垂直的直线。但是,我在首先指定曲线上的节点时遇到了麻烦,如果可以选择的话,我不想进行分析。我的代码如下:

\documentclass{article} 
\usepackage{tikz}
\tikzset{near start abs/.style={xshift=1cm}}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}[auto,bend right]
  \node (a) at (-2,3) {};
  \node (b) at (0,1) {};
  \node (c) at (2,3) {};
  \node (p1) at (-3,-3) {};
  \node (p2) at (0,-1) {};
  \node (p3) at (3,-3) {};
  \draw[->] (a) parabola bend (b) (c) coordinate[pos=0.5](A); % attempting to specify position along line for top curve
  \draw[->] (p1) parabola bend (p2) (p3) coordinate[pos=0.5](B);% attempting to specify position along line for bottom curve
  \coordinate (b1) at ($ (b)!.5!(c) $); % attempting to specify coordinate along line for top curve
  \coordinate (b2) at ($ (p2)!.33!(p3) $); % attempting to specify position along line for bottom curve
  \draw [<->] (b1) -- (b2) node [sloped,midway,above] {1cm};
  \draw [<->] (A) -- (B) node {1cm};
\end{tikzpicture}
\end{document}

其结果为:

在此处输入图片描述

然而,我试图制作的东西更像这样。我也在 tiki 中制作了它,但手动指定了线的起点和终点,使用坐标而不是节点,如果可能的话,我想避免这种情况,以使其更加通用。我被这个问题困扰了一段时间,所以任何帮助都将不胜感激!

在此处输入图片描述

答案1

一种方法是绘制函数,然后计算其给定的值\x

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                quotes}
\usepackage{siunitx}

\begin{document}
    \begin{tikzpicture}[
    auto, 
      > = Straight Barb,
samples = 51]
\draw[->, semithick]   plot [domain=-2:2] (\x, {+0.5+0.2*(\x)^2});
\draw[->, semithick]   plot [domain=-3:3] (\x, {-0.5-0.2*(\x)^2});
%
\draw[<->]  (1,{-0.5-0.2*(1)^2}) to ["\qty{1}{cm}", sloped]   ((1,{0.5+0.2*(1)^2});
    \end{tikzpicture}
\end{document}

在此处输入图片描述

附录: 因为在您的 MWE 中您加载了intersections库,所以让我使用它和任何曲线添加解决方案:

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                intersections,
                quotes}
\usepackage{siunitx}

\begin{document}
    \begin{tikzpicture}[auto, > = Straight Barb]
\draw[->, semithick, name path=A]   (-2,+2) .. controls +(0.5,-1) and +(-1,-1) .. (2,+1);
\draw[->, semithick, name path=B]   (-2,-2) .. controls +(0.5,+1) and +(-1,+1) .. (2,-2);
%
\path[name path=C] (1,2) -- (1,-2);
\coordinate [name intersections={of=A and C, by=a}];
\coordinate [name intersections={of=B and C, by=b}];
\draw[<->]  (b) to ["\qty{1}{cm}", sloped]   (a);
    \end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

我对使用 latex 和 tikz 还很陌生,所以这可能不是“最佳”方法,但这是我尝试制作底部图片的方法!

\documentclass{article} 
\usepackage{tikz}
\tikzset{near start abs/.style={xshift=1cm}}
\usetikzlibrary{calc}
\usetikzlibrary{intersections}

\begin{document}
\begin{tikzpicture}[auto,bend right]
  \node (a) at (-2,3) {};
  \node (b) at (0,1) {};
  \node (c) at (2,3) {};
  \node (p1) at (-3,-3) {};
  \node (p2) at (0,-1) {};
  \node (p3) at (3,-3) {};
  \draw[-] (a) parabola bend (b) (c) coordinate[pos=0.5](A); % attempting to specify position along line for top curve
  \draw[-] (p1) parabola bend (p2) (p3) coordinate[pos=0.5](B);% attempting to specify position along line for bottom curve
  \draw[<->] (1.5,2) -- (1.5,-1.4);
\end{tikzpicture}
\end{document}

这给了

在此处输入图片描述

相关内容