# How to reverse an intersection segment in TikZ (not pgfplots)

In a way, this is just a reminder of an old unsolved question but arguably with some new insight or tilt. (And I do not think the actual question is a duplicate of the old one.) The fillbetween library has the feature of providing access to intersection segments. I am aware of Heiko Oberdiek's statement that this might be not always precise, but I find that in many cases it is actually precise enough. IMHO the real problem is that reverse does not work in plain TikZ, while in pgfplots it just works fine. Consider this MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots} % loads tikz
\pgfplotsset{compat=1.15}
\usetikzlibrary{intersections,fillbetween}
\begin{document}
\begin{tikzpicture}
\path[name path = line1, draw] (-1,0) to[out=90,in=90] (1,1) to[out=-90,in=0]  (0,-1);
\path[name path = line2, draw] (-1,1) -- (1,-1);
\draw[very thick, intersection segments={of=line1 and line2,sequence=L2}];
\end{tikzpicture}

\begin{tikzpicture}
\path[name path = line1, draw] (-1,0) to[out=90,in=90] (1,1) to[out=-90,in=0]  (0,-1);
\path[name path = line2, draw] (-1,1) -- (1,-1);
\draw[very thick, intersection segments={of=line1 and line2,sequence=L1 R2}];
\end{tikzpicture}

% The following does not work.
%
% \begin{tikzpicture}
%     \path[name path = line1, draw] (-1,0) to[out=90,in=90] (1,1) to[out=-90,in=0]  (0,-1);
%     \path[name path = line2, draw] (-1,1) -- (1,-1);
%     \draw[very thick, intersection segments={of=line1 and
%   line2,sequence=L2[reverse] R2}];
% \end{tikzpicture}

\end{document}


If I were to uncomment the last part, I'd trigger an error. In fact, any attempt to make reverse work lead to an error.

QUESTION: Is there a (simple) way to fix this?

COMMENT: Once reverse works, the old unsolved question should be solved as well.

• Just add brace around L2[reverse] R2 -> {L2[reverse] R2} – Salim Bou Mar 24 '18 at 7:15
• pgfplots samples the path, tikz produces a standalone path. The segment marking is find the intersections points and converting into timer values. – percusse Mar 24 '18 at 8:56
• @SalimBou Seems to work. Want to shoot an answer? – user121799 Mar 24 '18 at 14:30

## 1 Answer

The syntax you are using seems to be wrong. See the pgfplots manual which has examples such as

\fill [
intersection segments={
of=f and border,
sequence={R2[reverse] -- L2}},
pattern=north west lines,
]
-- (rel axis cs:1,1) -- cycle;


in the explanation of the reverse (currently page 444 in Chapter 5), and notice that the sequence argument is contained in braces {...}.

The document below, corresponding to you last non-working code, works fine with this change:

\documentclass{article}

\usepackage{pgfplots}
\usetikzlibrary{intersections,fillbetween}
\pgfplotsset{compat=1.15}

\begin{document}

\begin{tikzpicture}
\path[name path = line1, draw] (-1,0) to[out=90,in=90] (1,1)
to[out=-90,in=0]  (0,-1);
\path[name path = line2, draw] (-1,1) -- (1,-1);
\draw[very thick, intersection segments={of=line1 and line2,
sequence={L2[reverse] R2}}];
\end{tikzpicture}

\end{document}