交叉点问题:没有已知的名为“intersection-1”的形状

交叉点问题:没有已知的名为“intersection-1”的形状

当我编译以下代码时出现错误,Package pgf Error: No shape named intersection-1 is known.我该如何修复它?

\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}

输出: 在此处输入图片描述

答案1

其中一条路径(名为 的虚线直线p2)有点短,因此在未缩放的版本中找不到交点。您需要做的就是使路径(不必与您绘制的虚线重合!)稍微长一点。

\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}

在此处输入图片描述

对我来说,这些看起来像舍入误差,类似于你所得到的这里和以前一样,我不知道一个简单的开关可以关闭它们。然而,当我写这个答案我发现这intersections实际上是一个很巧妙但也很复杂的代码。这让我怀疑是否存在一个简单的开关,因此我无法提供比这个解决方案或解决方法更好的东西。

相关内容