Next example (taken from TiKZ manual) shows how to find intersection points between two paths.
Once you know intersection points it's easy to decorate them with any marking. But if I want to use an arrow following the path I need to convert coordinate to position
(percentage of total length) over the path.
Do you know how to do it?
To draw the example I've used a trial and error method to place arrows. I would like to use (i-\s)
coordinates.
\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{intersections,decorations.markings}
\begin{document}
\begin{tikzpicture}[]
\clip (-2,-2) rectangle (2,2);
\draw [name path=curve 1] (-2,-1) .. controls (8,-1) and (-8,1) .. (2,1);
\draw [name path=curve 2] (-1,-2) .. controls (-1,8) and (1,-8) .. (1,2);
\fill [name intersections={of=curve 1 and curve 2, name=i, total=\t}]
[red, opacity=0.5, every node/.style={above left, black, opacity=1}]
\foreach \s in {1,...,\t}{(i-\s) circle (1pt) node {\footnotesize\s}};
\draw[decorate,decoration={
markings,%
mark=at position .72 with {\arrow[red,line width=1pt]{>}},%
mark=at position .595 with {\arrow[blue,line width=1pt]{>}},%
mark=at position .225 with {\arrow[green,line width=1pt]{>}}}]%
(-2,-1) .. controls (8,-1) and (-8,1) .. (2,1);
\end{tikzpicture}
\end{document}
EDIT: I will try to explain it better.
In my example I've used mark=at position .72
where .72
was decided after several drawings. I would like to use something like mark=at position corresponding to (i-4)
.
where (i-4)
is one of the intersection point or any other specific point over the path but with an unknown position
. This way would be possible to decorate a path with an arrow from, for example, (i-4) to (i-9) or would be possible to provide an exact answer to
Decorate path with arrows at nodes. Provided answers also position the arrow with some approximation and not with the precision that TiKZ shows us all around.