原始答案

原始答案

有没有更好的方法来绘制箭头直到它到达曲线?我刚刚对数字进行了硬编码,但想知道是否有办法标记曲线然后绘制直到曲线。

\begin{figure}[h!]
    \centering
    \begin{tikzpicture}
        \draw[thick, ->] (-0.5, 0) -- (3.5, 0) node[anchor=west] {$x$};
        \draw[thick, ->] (0, -0.5) -- (0, 1) node[anchor=south] {$y$};
        \fill (0, 0) circle (0.7mm) node[anchor=north east] {$O$};
        \draw[thick] (0, 0) .. controls (1, 1) and (2, 1) .. (3, 0);
        \draw[thick, ->] (0.5, 0) -- (0.5, 0.35);
        \draw[thick, ->] (1, 0) -- (1, 0.6);
        \draw[thick, ->] (1.5, 0) -- (1.5, 0.7);
        \draw[thick, ->] (2, 0) -- (2, 0.6);
        \draw[thick, ->] (2.5, 0) -- (2.5, 0.35);
    \end{tikzpicture}
\end{figure}

产生图像

在此处输入图片描述

答案1

有了一些交集,事情就变得简单了。我稍微改变了一下风格,但如果你不喜欢,只需向下滚动并获取原始版本中的以下代码。

输出

在此处输入图片描述

代码

\documentclass[tikz,margin=10pt]{standalone}
\usetikzlibrary{calc,intersections,arrows.meta}

\begin{document}
\begin{tikzpicture}[-{Stealth[scale=.8]}]
    \draw[thick, ->] (-0.5, 0) -- (3.5, 0) node[anchor=west] {$x$};
    \draw[thick, ->] (0, -0.5) -- (0, 1) node[anchor=south] {$y$};
    \fill (0, 0) circle (0.7mm) node[anchor=north east] {$O$};
    \draw[thick, name path=curve, -] (0, 0) .. controls (1, 1) and (2, 1) .. (3, 0);

\foreach \x [count=\xi] in {.25,.5,...,2.75}{
    \path[name path=a\xi] (\x,0) --++ (0,1);
    \path[name intersections={of=curve and a\xi, by=c\xi}];
    \draw[thick] (\x,0) -- (c\xi);
}
\end{tikzpicture}
\end{document}

原始答案

输出

在此处输入图片描述

代码

\documentclass[tikz,margin=10pt]{standalone}
\usetikzlibrary{calc,intersections,arrows.meta}

\begin{document}
\begin{tikzpicture}
    \draw[thick, ->] (-0.5, 0) -- (3.5, 0) node[anchor=west] {$x$};
    \draw[thick, ->] (0, -0.5) -- (0, 1) node[anchor=south] {$y$};
    \fill (0, 0) circle (0.7mm) node[anchor=north east] {$O$};
    \draw[thick, name path=curve] (0, 0) .. controls (1, 1) and (2, 1) .. (3, 0);

\foreach \x [count=\xi] in {.5,1,...,2.5}{
    \path[name path=a\xi] (\x,0) --++ (0,3);
    \path[name intersections={of=curve and a\xi, by=c\xi}];
    \draw[thick, ->] (\x,0) -- (c\xi);
}
\end{tikzpicture}
\end{document}

相关内容