2

Is there a better way to draw an arrow until it reaches the curve? I have just hard coded the numbers, but was wondering if there was a way to label the curve then draw until the curve.

\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}

produces the image

enter image description here

Alenanno
  • 37,338

1 Answers1

4

With some intersections, it gets easier. I have changed the style a bit, but if you don't like it, just scroll down and grab the code below in the original version.

Output

enter image description here

Code

\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}

Original answer

Output

enter image description here

Code

\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}
Alenanno
  • 37,338