# dash path between two intersections with other path

I wish to dash the red path when it is between the intersections with the blue path. How can I do this using paths names?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw [red , ultra thick,name path=A] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1).. controls +(1,0) and +(-1,0) .. (4,0) ;
\draw [ white , double=blue , ultra thick , double distance=1.6 pt, name path=B] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1) ;
\end{tikzpicture}
\end{document}


An alternative:

\documentclass[tikz]{standalone}
\makeatletter
\tikzset{recycle path/.code=\pgfsyssoftpath@invokecurrentpath#1}
\makeatother
\begin{document}
\begin{tikzpicture}
\path[save path=\pathA] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) ..
controls +(1,0) and +(-1,0) .. (4,1);
\begin{scope}
\clip[recycle path=\pathA] |- (0,1cm+1.4pt);
\draw [red , ultra thick,dashed] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1).. controls +(1,0) and +(-1,0) .. (4,0) ;
\end{scope}
\begin{scope}
\clip[recycle path=\pathA] -- (4,-0.4pt) -- (0,-0.4pt);
\draw [red , ultra thick] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1).. controls +(1,0) and +(-1,0) .. (4,0) ;
\end{scope}
\draw [white , double=blue , ultra thick , double distance=1.6 pt,use path=\pathA];
\end{tikzpicture}
\end{document}


This answer is community wiki because the code is not mine.

You can find intersections and clip inside relavant rectangle to draw the dashed curve.

\documentclass[tikz,border=5mm]{standalone}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
\draw[red,name path=A,save path=\pathA]
(0,0) .. controls +(1,0) and +(-1,0) ..
(2,1) .. controls +(1,0) and +(-1,0) .. (4,0);

\draw[blue,name path=B,save path=\pathB]
(0,1) .. controls +(1,0) and +(-1,0) ..
(2,0) .. controls +(1,0) and +(-1,0) .. (4,1);

\path[name intersections={of=A and B}]
(intersection-1) coordinate (M)
(intersection-2) coordinate (N)
(current bounding box.north) coordinate (P)
(current bounding box.south) coordinate (Q);
\path (M); \pgfgetlastxy{\Mx}{\My}
\path (N); \pgfgetlastxy{\Nx}{\Ny}
\path (P); \pgfgetlastxy{\Px}{\Py}
\path (Q); \pgfgetlastxy{\Qx}{\Qy}

\begin{scope}
\fill[white] (\Mx,\Qy) rectangle (\Nx,\Py);
\clip (\Mx,\Qy) rectangle (\Nx,\Py);
\draw[red,dashed,use path=\pathA];
\draw[blue,use path=\pathB];
\end{scope}

\end{tikzpicture}
\end{document}


A shorter code is as follows.

\begin{tikzpicture}
\draw[red,name path=A,save path=\pathA]
(0,0) .. controls +(1,0) and +(-1,0) ..
(2,1) .. controls +(1,0) and +(-1,0) .. (4,0);

\draw[blue,name path=B,save path=\pathB]
(0,1) .. controls +(1,0) and +(-1,0) ..
(2,0) .. controls +(1,0) and +(-1,0) .. (4,1);

\path[name intersections={of=A and B}]
(intersection-1) coordinate (M)
(intersection-2) coordinate (N)
(current bounding box.north) coordinate (P)
(current bounding box.south) coordinate (Q);

\begin{scope}
\fill[white] (M|-Q) rectangle (N|-P);
\clip (M|-Q) rectangle (N|-P);
\draw[red,dashed,use path=\pathA];
\draw[blue,use path=\pathB];
\end{scope}
\end{tikzpicture}

• I cannot compile your code. My program does not recognize the "use path" key. Did you miss a package here? – Victor Flux Radkow Jul 16 '19 at 10:34
• @VictorFluxRadkow Updating your Miktex, or using TexLive 2019 pls – Black Mild Jul 16 '19 at 10:38
• I'm using Texmaker 5.0.3, which is the latest version. – Victor Flux Radkow Jul 16 '19 at 10:46
• @VictorFluxRadkow It seems that you are very new to LaTeX and TikZ. TexMaker is just your cloths, meanwhile Miktex (or TexLive) is your body. So you need to update MikTex - your body: type Miktex console on the command line, then update with Administration previllege – Black Mild Jul 16 '19 at 11:13
• Yes I am new to Latex, but it was a bit hurtful to point it out. Thank you, now it works! Thank you very much for your answer and help! – Victor Flux Radkow Jul 16 '19 at 11:40