# Drawing path from intersection of two paths to origin of those two intersecting paths

I have two paths which are to be drawn with dotted lines (shown in figure) and they intersect at some point C.

Now I need to draw a resultant path of these two paths with solid lines. The resultant path should follow the original paths till they intersect. So in figure the resultant path will be following path 1 from A to C and then it should take path 2 to reach B.

The paths need not be straight lines as given in the MWE. So I am looking for a method to draw path from intersection of two paths to the origin of those paths in general.

\documentclass[margin=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\begin{document}
\begin{tikzpicture}
\draw[dotted, name path=p1] (-2,0)node(A){A} -- ++(0,1) -- ++(45:5cm)node(A1){A'};
\draw[dotted, name path=p2] (2,0)node(B){B} -- ++(0,1) -- ++(135:5cm)node(B1){B'};
\path [name intersections={of = p1  and p2,by=C}];
\draw (C)node[]{C};
\end{tikzpicture}
\end{document}


## 2 Answers

The pgfplots (!) library fillbetween allows you to use intersection segments of paths for all sorts of things, including (re)drawing.

\documentclass[margin=1cm]{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\begin{document}
\begin{tikzpicture}
\draw[dotted, name path=p1] (-2,0)node(A){A} -- ++(0,1) -- ++(45:5cm)node(A1){A'};
\draw[dotted, name path=p2] (2,0)node(B){B} -- ++(0,1) -- ++(135:5cm)node(B1){B'};
\path [name intersections={of = p1  and p2,by=C}];
\draw (C)node[]{C};
\draw [intersection segments={
of=p1 and p2,
sequence={L1 -- R1[reverse]}
}];
\end{tikzpicture}
\end{document}


• Thank you. It works fine. Just curious: Does the node names A0 and B0 has to do with the node names A and B that is used in the code? – nidhin Nov 5 '18 at 19:51
• @nidhin No, it does not. I rewrote my answer (also because the L and R syntax is newer. L refers to the first path and R to the second one. L1, L2 etc. are the intersection segments of the first path, similarly for R. See section 5.7.6 Intersection Segment Recombination of the pgfplots manual for more details. Note that this works for arbitrary paths, curves etc., and also for several intersections. – user121799 Nov 5 '18 at 19:58
• So L1 means second segment of 1st path? If so, L0 is the upper segment of 1st path. So the numbering is done is reverse order? – nidhin Nov 5 '18 at 20:04
• @nidhin No, AFAIK for the L and R syntax the numbering starts at 1 while it starts at 0 for the A and B syntax. (I can see how this is confusing.) – user121799 Nov 5 '18 at 20:06
• @nidhin Yes, it is somewhat confusing. Notice that L0 -- R0 works sort of by accident, the path between A' and C is drawn twice in two directions. You can check that by drawing the path dashed. – user121799 Nov 5 '18 at 20:32

If like in your code, you know what's the path to be drawn, you can redraw it by hand (1st example). Another option could be to clip the original figure to just show the desired part (2nd example). In this second case, the join at C.center is shorter than in first case.

\documentclass[margin=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc,intersections}
\begin{document}
\begin{tikzpicture}
\draw[dotted, name path=p1] (-2,0)node(A){A} -- ++(0,1) -- ++(45:5cm)node(A1){A'};
\draw[dotted, name path=p2] (2,0)node(B){B} -- ++(0,1) -- ++(135:5cm)node(B1){B'};
\path [name intersections={of = p1  and p2,by=C}] (C) node{C};
%\draw (C)node[]{C};

\draw (A.center)--++(0,1)--(C.center)--([yshift=1cm]B.center)--(B.center);
\end{tikzpicture}

\begin{tikzpicture}
\draw[dotted, name path=p1] (-2,0)node(A){A} -- ++(0,1) -- ++(45:5cm)node(A1){A'};
\draw[dotted, name path=p2] (2,0)node(B){B} -- ++(0,1) -- ++(135:5cm)node(B1){B'};
\path [name intersections={of = p1  and p2,by=C}] (C) node{C};
%\draw (C)node[]{C};
{
\clip (A.west|-C) rectangle (B.south east);
\draw (-2,0) -- ++(0,1) -- ++(45:5cm);
\draw (2,0) -- ++(0,1) -- ++(135:5cm);
}
%\draw (A.center)--++(0,1)--(C.center)--([yshift=1cm]B.center)--(B.center);
\end{tikzpicture}
\end{document}


• Thank you. Both works fine for this example. The paths that I need to draw include shapes other than straight lines. Can we follow the first method in that case also ? – nidhin Nov 5 '18 at 19:48
• @nidhin If "other shapes" means well know arcs probably yes, but for other kind of curves probably not. – Ignasi Nov 6 '18 at 8:45