2

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

AndréC
  • 24,137
Fabian
  • 45

1 Answers1

4

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}

enter image description here

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.