[Tex/LaTex] How to draw a (colored) arrow on a path

tikz-arrowstikz-pgf

I tried to draw a path and a curve length marker. This is the desired result:

desired output

This would be easy if the curve was defined as a function, then I'd just set the domain, add some markers, done. But what about more complicated paths, such as bézier curves?

I have a solution, but this is somewhat hacky and hard-coded.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[scale=2]
\coordinate (P) at (2.5,2) {};
\coordinate (Q) at (2.5,3) {};
\draw[ postaction={decorate,decoration={markings, mark=at position 0.245 with {\arrow[scale=1.2, blue]{stealth}}, 
mark=at position 0.17 with {\draw[blue, -, thick] (0,-0.6mm) --    (0,0.6mm) node[below right] {$s=0$};}}}] (0,0) to [in=200, out=70] (P)    to[out=20, in=170] (5,1.5);

\begin{scope}
    \clip(0.5,0) rectangle (0.8, 1.6);
    \draw[thick, blue] 
    (0,0) to [in=200, out=70] (2.5,2) to[out=20, in=230] (5,1.5) ;
\end{scope}

\end{tikzpicture}
\end{document}

(The reason for not putting the markers inside the second curve is that if I did that, at least the left marker would be clipped, too)

As a first step, I'd like to remove the hard coded numbers from scope and decorations.

Any ideas how to improve that (ugly) bit of code?

As a bonus, it would be cool to have a node with "s" in the middle of the blue line.

Best Answer

edit (2): in the first solution the definition of clip area doesn't work in all circumstances. with some small changes in provided code escape this limitation

see if the following code is close to what you looking for:

\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, calc, decorations.markings, quotes}

\begin{document}
\begin{tikzpicture}[auto=right, scale=2]
\newcommand\clipshape[1]{($(a)!#1!90:(b)$) -- ($(b)!#1!-90:(a)$) --
                         ($(b)!#1!90:(a)$) -- ($(a)!#1!-90:(b)$) -- cycle} % added
\coordinate (P) at (2.5,2) {};
\draw[ postaction={decorate,decoration={markings,
    mark=at position 0.17 with {\coordinate (a); % changed
                                \arrow[blue,thick]{Bar[width=1.2mm]}},
    mark=at position 0.24 with {\coordinate (b); % changed
                                \arrow[blue,thick,xshift=2\pgflinewidth]{Stealth}},
        }}]
    (0,0) to [in=200, out=70] (P)
          to [out=20, in=170] (5,1.5);

    \path (a) to [inner sep=1pt, "$s=0$"] (b); % changed
    \path[clip] \clipshape{2mm}; % changed
    \draw[thick, blue]
    (0,0) to [in=200, out=70] (P) to [out=20, in=170] (5,1.5);
\end{tikzpicture}
\end{document}

enter image description here

edit (1): to see effect of \clipshape, change it content to:

    \draw[thick, red, semitransparent]
    (0,0) to [in=200, out=70] (P) 
          to [out=20, in=170] (5,1.5) ;

enter image description here

now the position of node with s=0 is always adapted to slope of line.