dash path between two intersections with other path

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

enter image description here

\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}

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}

enter image description here

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


Version 2.0 of the spath3 package introduces routines to split curves at intersection points and then render their components with different styles. Using that, your diagram can be coded as follows. Note that to get the crossing effect I insert actual gaps in the paths rather than using the wipe-out technique.

\documentclass{article}
%\url{https://tex.stackexchange.com/q/500081/86}
\usepackage{tikz} 
\usetikzlibrary{intersections, spath3}
\begin{document}
\begin{tikzpicture}
\path [spath/save=A] (0,0) .. controls +(1,0) and +(-1,0) .. (2,1).. controls +(1,0) and +(-1,0) .. (4,0) ; 
\path [spath/save=B] (0,1) .. controls +(1,0) and +(-1,0) .. (2,0) .. controls +(1,0) and +(-1,0) .. (4,1) ;

\tikzset{
  spath/split at intersections={A}{B},
  spath/spot weld=B,
  spath/insert gaps after components={A}{5pt}{1,2},
  spath/get components of=A\Acpts
}

\draw[blue, ultra thick, spath/restore=B];

\tikzset{
  every A component/.style={ultra thick, red, draw},
  A component 2/.style={dashed},
  spath/render components=A,
}

\end{tikzpicture}
\end{document}

Braid with dashed component.