5

When I compile the following code I get the error Package pgf Error: No shape named intersection-1 is known. How can I fix it?

\documentclass[tikz,border=5mm]{standalone}

\usetikzlibrary{intersections}
\usetikzlibrary{through,calc,decorations.markings,positioning,angles}
\usepackage{fp}
\usepgflibrary{fixedpointarithmetic}


\tikzset{
  tangent/.style={
        decoration={
            markings,% switch on markings
            mark=
                at position #1
                with
                {   
                    \coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
                    \coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
                    \coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
                }
        },
        postaction=decorate
    },
    use tangent/.style={
        shift=(tangent point-#1),
        x=(tangent unit vector-#1),
        y=(tangent orthogonal unit vector-#1)
    },
    use tangent/.default=1
  }

\begin{document}
\begin{tikzpicture}[
    % Style for the spy nodes and the connection line
    spy/.style={%
        draw,orange,
        line width=1pt,
        circle,inner sep=0pt,
    },
]
    % Parameters

    %% size of the spy-in nodes
    \def\spyviewersize{5.25cm}

    %% (line width of the spy nodes) / 2
    %% we need this for clipping later
    \def\spyonclipreduce{0.5pt}

    %% first zoom
    %%% factor
    \def\spyfactorI{15}
    %%% spy in point
    \coordinate (spy-in 1) at (8,0);
    %%% spy on point
    \pgfmathsetmacro{\a}{2}
    \pgfmathsetmacro{\b}{1.5}
    \pgfmathsetmacro{\al}{30}
%    \coordinate (spy-on 1) at ({\a*cos(\al)},{\b*sin(\al)});% sould be on the curve
    \pgfmathsetmacro{\fk}{0.97}
    \pgfmathsetmacro{\wk}{\al*\fk}      
    \pgfmathsetmacro{\rP}{sqrt((\a*cos(\al))^2 + (\b*sin(\al))^2)}

    %% the graph/picture
    \def\pik{
      \draw[dashed,fill,brown,opacity=0.4] (0,0) coordinate (O) circle (\b);

      \draw[tangent={\al/360},blue,thick] plot[domain=0:360,samples=400]
      ({\a*cos(\x)},{\b*sin(\x)});
      \draw[use tangent,blue,thick,dashed] (-2.5,0) -- (2.5,0) coordinate (XA);
      \node[fill,circle,inner sep=0pt,minimum size=2pt] (P) at
      (tangent point-1) {};
      \node [draw,gray,name path=kr] at (O) [circle through=(P)] {};
      \node[fill,circle,inner sep=0pt,minimum size=2pt] (P2) at
      ({\a*cos(\wk)},{\b*sin(\wk)}) {};
      \draw (O) --node[above,sloped]{$r$} (P);
      \draw[dotted,name path=p2] (O) -- (P2);
      \path [name intersections={of=kr and p2,by=S}]; 
      \node[fill,circle,inner sep=0pt,minimum size=2pt] (P2) at
      (S) {};
      \draw[ultra thick,opacity=0.5] (S) -- (P2);
      \draw ($(P)!1cm!90:(O)$) -- ($(P)!1cm!-90:(O)$);
      \node[right] at (P) {$P$};
    }


    % draw the original picture
    \pik
    \coordinate (spy-on 1) at (tangent point-1);% sould be on the curve
    % first zoom
    %% spy on node
    \node[spy,minimum size={\spyviewersize/\spyfactorI}] (spy-on node 1) at (spy-on 1) {};
    %% spy in node
    \node[spy,minimum size=\spyviewersize] (spy-in node 1) at (spy-in 1) {};
    \begin{scope}
        \clip (spy-in 1) circle (0.5*\spyviewersize-\spyonclipreduce);
        \pgfmathsetmacro\sI{1/\spyfactorI}
        \begin{scope}[
            shift={($\sI*(spy-in 1)-\sI*(spy-on 1)$)},
            scale around={\spyfactorI:(spy-on 1)},
        ]
        \pik
        %%
        % \pic[draw,angle radius=50,fill=blue!50]{%
        % angle=XB--tangent point-1--XA};
        % \coordinate (aux) at (barycentric cs:XA=1,XB=1,tangent point-1=1);
%        \node[right=4mm of aux] (phi){$\varphi$};
        %\draw[-latex] (phi) to[bend right](aux);
        %% How to interpret the measure 50 for the angle radius
        \end{scope}
    \end{scope}
    %% connect the nodes
    \draw [spy] (spy-on node 1) -- (spy-in node 1);
\end{tikzpicture}
\end{document}

Output: enter image description here

4

One of the paths (the dotted straight line named p2) is a bit short such that in the unzoomed version the intersection cannot be found. All you need to do is to make the path (which does not have to coincide with the dashed line that you draw!) a tiny bit longer.

\documentclass[tikz,border=5mm]{standalone}

\usetikzlibrary{intersections}
\usetikzlibrary{through,calc,decorations.markings,positioning,angles}
\usepackage{fp}
\usepgflibrary{fixedpointarithmetic}


\tikzset{
  tangent/.style={
        decoration={
            markings,% switch on markings
            mark=
                at position #1
                with
                {   
                    \coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
                    \coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
                    \coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
                }
        },
        postaction=decorate
    },
    use tangent/.style={
        shift=(tangent point-#1),
        x=(tangent unit vector-#1),
        y=(tangent orthogonal unit vector-#1)
    },
    use tangent/.default=1
  }

\begin{document}
\begin{tikzpicture}[
    % Style for the spy nodes and the connection line
    spy/.style={%
        draw,orange,
        line width=1pt,
        circle,inner sep=0pt,
    },
]
    % Parameters

    %% size of the spy-in nodes
    \def\spyviewersize{5.25cm}

    %% (line width of the spy nodes) / 2
    %% we need this for clipping later
    \def\spyonclipreduce{0.5pt}

    %% first zoom
    %%% factor
    \def\spyfactorI{15}
    %%% spy in point
    \coordinate (spy-in 1) at (8,0);
    %%% spy on point
    \pgfmathsetmacro{\a}{2}
    \pgfmathsetmacro{\b}{1.5}
    \pgfmathsetmacro{\al}{30}
%    \coordinate (spy-on 1) at ({\a*cos(\al)},{\b*sin(\al)});% sould be on the curve
    \pgfmathsetmacro{\fk}{0.97}
    \pgfmathsetmacro{\wk}{\al*\fk}      
    \pgfmathsetmacro{\rP}{sqrt((\a*cos(\al))^2 + (\b*sin(\al))^2)}

    %% the graph/picture
    \def\pik{
      \draw[dashed,fill,brown,opacity=0.4] (0,0) coordinate (O) circle (\b);

      \draw[tangent={\al/360},blue,thick] plot[domain=0:360,samples=400]
      ({\a*cos(\x)},{\b*sin(\x)});
      \draw[use tangent,blue,thick,dashed] (-2.5,0) -- (2.5,0) coordinate (XA);
      \node[fill,circle,inner sep=0pt,minimum size=2pt] (P) at
      (tangent point-1) {};
      \node [draw,gray,name path=kr] at (O) [circle through=(P)] {};
      \node[fill,circle,inner sep=0pt,minimum size=2pt] (P2) at
      ({\a*cos(\wk)},{\b*sin(\wk)}) {};
      \draw (O) --node[above,sloped]{$r$} (P);
      \draw[dotted] (O) -- (P2) coordinate[pos=1.1] (aux);
      \path[name path=p2] (O) -- (aux);
      \path [name intersections={of=kr and p2,by=S}] 
      node[fill,circle,inner sep=0pt,minimum size=2pt] (P2) at
      (S) {};
      \draw[ultra thick,opacity=0.5] (S) -- (P2);
      \draw ($(P)!1cm!90:(O)$) -- ($(P)!1cm!-90:(O)$);
      \node[right] at (P) {$P$};
    }


    % draw the original picture
    \pik
    \coordinate (spy-on 1) at (tangent point-1);% sould be on the curve
    % first zoom
    %% spy on node
    \node[spy,minimum size={\spyviewersize/\spyfactorI}] (spy-on node 1) at (spy-on 1) {};
    %% spy in node
    \node[spy,minimum size=\spyviewersize] (spy-in node 1) at (spy-in 1) {};
    \begin{scope}
        \clip (spy-in 1) circle (0.5*\spyviewersize-\spyonclipreduce);
        \pgfmathsetmacro\sI{1/\spyfactorI}
        \begin{scope}[
            shift={($\sI*(spy-in 1)-\sI*(spy-on 1)$)},
            scale around={\spyfactorI:(spy-on 1)},
        ]
        \pik
        %%
        % \pic[draw,angle radius=50,fill=blue!50]{%
        % angle=XB--tangent point-1--XA};
        % \coordinate (aux) at (barycentric cs:XA=1,XB=1,tangent point-1=1);
%        \node[right=4mm of aux] (phi){$\varphi$};
        %\draw[-latex] (phi) to[bend right](aux);
        %% How to interpret the measure 50 for the angle radius
        \end{scope}
    \end{scope}
    %% connect the nodes
    \draw [spy] (spy-on node 1) -- (spy-in node 1);
\end{tikzpicture}
\end{document}

enter image description here

To me these look like rounding errors, similar to what you had here. As before, I do not know a simple switch to turn them off. However, when I wrote this answer I found that intersections is actually a brilliant but also complex code. This makes me doubt that there is a simple switch, and therefore I cannot offer anything better than this solution or workaround.

| improve this answer | |
  • Thanks, now it compiles, but the path \draw[ultra thick,opacity=0.5] (S) -- (P2); doesn't seem to be drawn. Is this also due to rounding errors? – Julia Nov 7 '18 at 16:41
  • @Julia No, this is because you place the node P2 at S when you say (P2) at (S). So this is a path of length 0. – user121799 Nov 7 '18 at 16:45
  • Oh, thanks. Just a stupid copy and past error. – Julia Nov 7 '18 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.