Finding an intersection with respect to the decoration

in Naming nodes in a decoration and draw lines from node to node I asked a question, which was answered. The most help was the following.

    \documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.markings}
\begin{document}
\begin{tikzpicture}[
decoration={
markings,
mark=at position 0.4 with {\draw[->] (0,0)--(0,1);
\draw[->] (0,0)--(2,-2) node[below]{A};
\draw[<-] (0,0)--(-.8,-.8);}
}
]
\draw[postaction={decorate}] plot [smooth cycle] coordinates {(0,0) (1,1) (3,1) (3,0) (2,-1)};
\end{tikzpicture}
\end{document}


Now, being able to draw those lines and naming the point, the follow up question is: Can I find the intersection of A with the smooth plot in relation to the smooth plot. I'd like the intersection in terms of pos=.3 or something, so can do a decoration at the intersection. Is it possible and how can it be done?

Thanks a lot. Greetings Fabian

• A is a node. What you mean by intersection of A with plot? – nidhin Nov 23 '18 at 9:04
• A was the name i gave to the arrow to distinguish it. Sorry for the bad naming. – Fabian Nov 23 '18 at 9:12

This question is actually less innocent than it might appear to you. Luckily pgfplots (!) has its means to decompose a path into intersection segments, which, in turn, one can decorate. In this MWE

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.markings}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\draw[postaction={decorate,decoration={
markings,
mark=at position 0.4 with {\draw[->] (0,0)--(0,1);
\draw[->,name path=pathA] (0,0)--(2,-2) node[below]{A};
\draw[<-] (0,0)--(-.8,-.8);}
}},name path global=pathB] plot [smooth cycle] coordinates {(0,0) (1,1) (3,1) (3,0) (2,-1)};
\path[ draw=blue,
postaction={decoration={
markings,
mark=at position 1 with {\draw[->] (0,0)--(0,1);}
},decorate},
intersection segments={of=pathA and pathB,
sequence={R2},
},];
\end{tikzpicture}
\end{document}


I compute (and draw in blue for illustration purposes) the intersection segment to the point where the original smooth plot intersects with the line labeled A. This point with now have position 1 in the segment. One can then e.g. draw a normal vector at this point.

• I'm always learning new features from you! – CarLaTeX Nov 23 '18 at 12:50
• @CarLaTeX Just don't tell your doctor that you are learning things from a marmot, bad things could happen. ;-) – user121799 Nov 23 '18 at 20:03
• Lol, my ducktor! – CarLaTeX Nov 23 '18 at 20:04