3

How may I interrupt one of the two crossing curved paths (arrows) shown below so that it appears to "duck underneath" the other one? (I don't care which one ducks under the other.)

I have the intersection point. Now what?

Note that for now I do not need to make a little half-circle on the "top" one of the two curves for indicating it's on top and crossing over the other one.

\documentclass[tikz,border=3pt]{standalone}
\usetikzlibrary{calc,spath3,intersections}

\begin{document}
\begin{tikzpicture}
    \coordinate (yy) at (6.8, -0.4);
    \coordinate (ww) at (7.75, 0.7625);
    \coordinate (pp) at (0.75,-2.25);
    \coordinate (qq) at (2.5,-2.25);

    \begin{scope}
        \draw[->,name path=pparrowyy,green,semithick,densely dashed,shorten <=5pt,shorten >=5pt] (pp) to[out=-30,in=230] (yy);
        \coordinate (ctrl) at (9,-1.5);
        \draw[->,name path=qqarrowww,orange,semithick,densely dashed,shorten <=5pt,shorten >=5pt] (qq) to[out=-50,in=200] (ctrl) to[out=20,in=0] (ww);
        \path [name intersections={of=pparrowyy and qqarrowww}];
    \end{scope}
\end{tikzpicture}

\end{document}

crossing curves

Added Per Andrew Stacey's comment, I tried this:

\documentclass[tikz,border=3pt]{standalone}
\usetikzlibrary{calc,spath3,intersections}

\begin{document}
\begin{tikzpicture}
    \coordinate (yy) at (6.8, -0.4);
    \coordinate (ww) at (7.75, 0.7625);
    \coordinate (pp) at (0.75,-2.25);
    \coordinate (qq) at (2.5,-2.25);

    \begin{scope}
        \draw[->,spath/save=pparrowyy,green,semithick,densely dashed,shorten <=5pt,shorten >=5pt] (pp) to[out=-30,in=230] (yy);
        \coordinate (ctrl) at (9,-1.5);
        \path[->,spath/save=qqarrowww] (qq) to[out=-50,in=200] (ctrl) to[out=20,in=0] (ww);
        \draw[spath/use=qqarrowww,spath/split at intersections with={pparrowyy}{qqarrowww},orange,semithick,densely dashed,shorten <=5pt,shorten >=5pt];
    \end{scope}
\end{tikzpicture}

\end{document}

However,2nd (orange) path does not seem to interrupt the green at the intersection (or vice versa).

What am I misunderstanding or otherwise doing wrong?

3
  • I see you're loading the spath3 library. If you look in the documentation for that library then you'll see examples of how to do this. Commented Jun 13 at 18:03
  • @AndrewStacey: I read description of "split at intersections" but obviously do not understand how to use it. E.g., I don't understand in the examples on pages 19ff what spath/.cd means in the \tikzset command.
    – murray
    Commented Jun 13 at 18:48
  • Linking to: tex.stackexchange.com/q/17181/86 Commented Jun 14 at 5:38

2 Answers 2

4

In this example, spath3 is probably overkill. It is easier to simply draw the second line twice: first in white (or whatever the page color is) with large line width (5pt in this example), and then draw it again in green with the desired style.

enter image description here

\documentclass[tikz,border=3pt]{standalone}

\begin{document}
\begin{tikzpicture}
    \coordinate (yy) at (6.8, -0.4);
    \coordinate (ww) at (7.75, 0.7625);
    \coordinate (pp) at (0.75,-2.25);
    \coordinate (qq) at (2.5,-2.25);
        \coordinate (ctrl) at (9,-1.5);
        \draw[orange, semithick, densely dashed, shorten <=5pt, shorten >=5pt] (qq) to[out=-50,in=200] (ctrl) to[out=20,in=0] (ww);
        \draw[line width=5pt, white, shorten <=5pt, shorten >=5pt] (pp) to[out=-30,in=230] (yy);
        \draw[->, green, semithick, densely dashed, shorten <=5pt, shorten >=5pt] (pp) to[out=-30,in=230] (yy);
\end{tikzpicture}

\end{document}

As @cfr suggests, you can make a style to accomplish this as a preaction. The output of the following is the same.

\documentclass[tikz,border=3pt]{standalone}

\tikzset{go over/.style={preaction={draw, line width=5pt, white}}}

\begin{document}
\begin{tikzpicture}
    \coordinate (yy) at (6.8, -0.4);
    \coordinate (ww) at (7.75, 0.7625);
    \coordinate (pp) at (0.75,-2.25);
    \coordinate (qq) at (2.5,-2.25);
        \coordinate (ctrl) at (9,-1.5);
        \draw[orange, semithick, densely dashed, shorten <=5pt, shorten >=5pt] (qq) to[out=-50,in=200] (ctrl) to[out=20,in=0] (ww);
        \draw[go over, ->, green, semithick, densely dashed, shorten <=5pt, shorten >=5pt] (pp) to[out=-30,in=230] (yy);
\end{tikzpicture}

\end{document}
3
  • Or you could use preaction or postaction to avoid repeating the construction. [Of course, you're assuming the OP doesn't want the lovely brick wall background from spath3's docs ;).]
    – cfr
    Commented Jun 13 at 20:01
  • Good point @cfr.
    – Sandy G
    Commented Jun 13 at 21:00
  • @SandyG: That works perfectly, but it seems like a "cheat" to draw a white envelope around one of the curves. I'm stiil hoping for another approach, since this kind of thing is something I will need to generalize.
    – murray
    Commented Jun 14 at 1:36
5

.cd just changes the directory so after spath/.cd, every key is read as if you'd prefixed it with spath/. Hence,

spath/.cd,
bob=red,
carol=blue,

is equivalent to

spath/bob=red,
spath/carol=blue,

While spath3 is probably overkill here, since the case you're interested in is relatively simple, this may make it a particularly useful example for experimental and/or pedagogical purposes ;).

We start by defining a convenience style to reduce clutter.

\begin{tikzpicture}[
    fancy dashed/.style={semithick,densely dashed,shorten <=5pt,shorten >=5pt},
  ]

We then define our coordinates and save the two paths.

  \coordinate (yy) at (6.8,-0.4);
  \coordinate (ww) at (7.75,0.7625);
  \coordinate (pp) at (0.75,-2.25);
  \coordinate (qq) at (2.5,-2.25);
  \coordinate (ctrl) at (9,-1.5);  

We don't draw the path we want to have gaps in.

  \path[->,spath/save=pparrowyy] (pp) to[out=-30,in=230] (yy);

But we may as well draw the other one immediately.

  \path[->,spath/save=qqarrowww,draw,orange,fancy dashed] (qq) to[out=-50,in=200] (ctrl) to[out=20,in=0] (ww);  

Now we use the spath3/intersections box of magic tricks.

  \tikzset{%

Change to the key path of interest.

    spath/.cd,

Split the paths. (Please don't use names like these for examples!)

    split at intersections={pparrowyy}{qqarrowww},

Now insert the gaps into the path we haven't drawn yet.

    insert gaps after components={pparrowyy}{2.5pt}{1,2},

And grab the components so we can draw them.

    get components of={pparrowyy}\pparrowyyComponents,
  }

Now iterate through the components (all 2 of them!), drawing each one.

  \foreach \comp in \pparrowyyComponents \path [spath/use=\comp,draw,green,fancy dashed];
\end{tikzpicture}

gappy path 'under' another

Complete code:

\documentclass[tikz,border=3pt]{standalone}
\usetikzlibrary{spath3,intersections}

\begin{document}
\begin{tikzpicture}[
    fancy dashed/.style={semithick,densely dashed,shorten <=5pt,shorten >=5pt},
  ]
  \coordinate (yy) at (6.8,-0.4);
  \coordinate (ww) at (7.75,0.7625);
  \coordinate (pp) at (0.75,-2.25);
  \coordinate (qq) at (2.5,-2.25);
  \coordinate (ctrl) at (9,-1.5);  
  \path[->,spath/save=pparrowyy] (pp) to[out=-30,in=230] (yy);
  \path[->,spath/save=qqarrowww,draw,orange,fancy dashed] (qq) to[out=-50,in=200] (ctrl) to[out=20,in=0] (ww);  
  \tikzset{%
    spath/.cd,
    split at intersections={pparrowyy}{qqarrowww},
    insert gaps after components={pparrowyy}{2.5pt}{1,2},
    get components of={pparrowyy}\pparrowyyComponents,
  }
  \foreach \comp in \pparrowyyComponents \path [spath/use=\comp,draw,green,fancy dashed];
\end{tikzpicture}
  
\end{document}
11
  • Fabulous! (And some more characters to get over the limit) Commented Jun 13 at 20:17
  • 1
    Not at all! It's a superb answer - really well explained. I'm bookmarking it as my canonical explanation of how to achieve this. Commented Jun 13 at 20:36
  • 1
    \path [spath/use=pparrowyy,draw,green,fancy dashed]; should work (I can't test on this device). Commented Jun 13 at 22:10
  • 1
    Ah, I hadn't looked carefully at the various styles. fancy dashed includes the two shorten keys. When drawing the full path then these get applied to the start and end of just the full path, when drawing the components individually then they get applied to each component. In reality, they should be applied when the path is constructed but not when it is rendered. Worth drawing the pparrowyy path when it is first defined with a thick line width so both the original and modified path can be seen together. Commented Jun 14 at 5:35
  • 1
    @cfr: this is enormously instructive and useful to me. thank you so much for taking the time to write the detailed and clear explanation. That's exactly the sort of thing that's hard for a TikZ beginner to suss out from the manual (and believe me, I'm no newbie when it comes to reading terse manuals, including for J and earlier, skimpir-documented, versions of Wolfram/Mathematica).
    – murray
    Commented Jun 14 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .