9

I've been trying to rotate a line around an intersection. The problem (I think) is that the intersection is in a previous scope (I need that to have the correct clipping), and the new scope doesn't know what (intersection-1) is. I've been trying the following:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
        \clip (0,0) circle (5);
    \begin{scope}
        \clip [name path=clipA] (0,0) -- (-30:25) -- (-150:25) -- cycle;
        \fill[name path=SpeciesA, blue, line cap = round] (-0.2,0) -- (-0.2,-4) -- (0.2,-4) --  node[sloped, below] {Species A} (0.2,0) -- cycle;
        \tikz\name intersections={of=clipA and SpeciesA}
    \end{scope}
    \begin{scope}
        \clip [(0,0) -- (-30:25) -- (90:25) -- cycle;
        \fill[blue!60!red, line cap = round, rotate around={150:(intersection-1)}] 
        (-0.2,0) -- node[rotate= 150, sloped, below] {Species C} (-0.2,-3) -- (0.2, -3) -- (0.2, 0) -- cycle; 
    \end{scope}
    \begin{scope}
        \clip (0,0) -- (-150:25) -- (90:25) -- cycle;
        \fill[blue!60!green, line cap = round, rotate=210] (-0.2,0) -- (-0.2,-3) -- (0.2, -3) --  node[rotate= 210, sloped, below] {Species B} (0.2, 0) -- cycle ; 
    \end{scope}
\end{tikzpicture}
\end{document}

As I say, LaTeX doesn't seem to know what (intersection-1) is, once we get there. Any advice?

Thanks

1

2 Answers 2

13

You can use name path global instead of name path to make the paths available for finding the intersections in a different scope. Note that you shouldn't use name intersection like a macro with \tikz, but instead use it as an option in a \path command (or similar).

As percusse pointed out, instead of using name path global you can also find the intersection within the scope where the lines are named, by using path[name intersections={of=clipA and SpeciesA}];. The intersections are nodes, so they are available globally (even in other tikzpictures!) as intersection-1, intersection-2, and so on.

References:

Code:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
        \clip (0,0) circle (5);
    \begin{scope}
        \clip [name path global=clipA] (0,0) -- (-30:25) -- (-150:25) -- cycle;
        \fill[name path global=SpeciesA, blue, line cap = round] (-0.2,0) -- (-0.2,-4) -- (0.2,-4) --  node[sloped, below] {Species A} (0.2,0) -- cycle;
    %    \tikz        \end{scope}
    \begin{scope}
        \clip (0,0) -- (-30:25) -- (90:25) -- cycle;
        \fill[name intersections={of=clipA and SpeciesA},blue!60!red, line cap = round, rotate around={150:(intersection-1)}] 
        (-0.2,0) -- node[rotate= 150, sloped, below] {Species C} (-0.2,-3) -- (0.2, -3) -- (0.2, 0) -- cycle; 
    \end{scope}
    \begin{scope}
        \clip (0,0) -- (-150:25) -- (90:25) -- cycle;
        \fill[blue!60!green, line cap = round, rotate=210] (-0.2,0) -- (-0.2,-3) -- (0.2, -3) --  node[rotate= 210, sloped, below] {Species B} (0.2, 0) -- cycle ; 
    \end{scope}
\end{tikzpicture}
\end{document}
9
  • I've replaced the problematic line with \path[name intersections={of=clipA and SpeciesA}]; and removed the third clip and it also works similarly.
    – percusse
    Jun 14, 2012 at 16:00
  • @percusse: Ah yes, you're right, you can find the intersection within the scope where the paths are named, the intersection-1 node will automatically be available globally.
    – Jake
    Jun 14, 2012 at 16:03
  • Thanks a lot. This is what I needed to know. The path[name intersections...] syntax was elluding me.
    – Schiphol
    Jun 14, 2012 at 16:31
  • I'm sorry, I'm new to stackexchange. How do I mod this answer up? Apparently I can't, but I wouldn't want to breach the netiquette by not giving positive feedback.
    – Schiphol
    Jun 14, 2012 at 16:32
  • @ManoloMartínez: You should be able to click on the upward pointing arrow next to the answer to upvote it, and there should be tick mark next to the answer that you can click to accept it.
    – Jake
    Jun 14, 2012 at 16:56
8

Yes (intersection-1) is known, but there are two problems in your code. If you remove them, your code compiles fine.

1) \tikz\name intersections={of=clipA and SpeciesA} ? why \tikz here and \name ? ??

2) \clip [(0,0) -- (-30:25) -- (90:25) -- cycle; why the [( ?

The next code compiles

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}
        \clip (0,0) circle (5);
    \begin{scope}
        \clip [name path=clipA] (0,0) -- (-30:25) -- (-150:25) -- cycle;
        \fill[name path=SpeciesA, blue, line cap = round] 
        (-0.2,0) -- (-0.2,-4) -- (0.2,-4) --  node[sloped, below] {Species A} (0.2,0) -- cycle;
        \path[name intersections={of=clipA and SpeciesA}];
    \end{scope}
    \begin{scope}
        \clip (0,0) -- (-30:25) -- (90:25) -- cycle;
        \fill[blue!60!red, line cap = round, rotate around={150:(intersection-1)}] 
        (-0.2,0) -- node[rotate= 150, sloped, below] {Species C} (-0.2,-3) -- (0.2, -3) -- (0.2, 0) -- cycle; 
    \end{scope}    
    \begin{scope}
        \clip (0,0) -- (-150:25) -- (90:25) -- cycle;
        \fill[blue!60!green, line cap = round, rotate=210] 
        (-0.2,0) -- (-0.2,-3) -- (0.2, -3) --  node[rotate= 210, sloped, below] {Species B} (0.2, 0) -- cycle ; 
    \end{scope}   
\end{tikzpicture}
\end{document}

You must log in to answer this question.

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