4

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}

enter image description here

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.

1 Answers1

3

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:

Sample output

\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}
Andrew Swann
  • 95,762