TikZ:扩展 tikz 图片环境

TikZ:扩展 tikz 图片环境

如果我缩放 TikZ 图片环境,所有内容都应该按正确的比例缩放x

如果是这样的话,为什么某些代码在环境中无法扩展或扩展不正确?

例如,

 \begin{tikzpicture}[scale = 3]
   code
 \end{tikzpicture}

我询问的原因是,当我输入缩放值作为环境选项时,Qrrbrbirlbel 帮助的一些代码无法缩放。

当我缩放图片时,出现以下错误:

ERROR: Package pgf Error: No shape named F'-2 is known.

--- TeX said ---

See the pgf package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.62       }
                                     %!?
--- HELP ---
From the .log file...

以下是代码:

\documentclass[convert = false]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc, intersections}

\begin{document}
\tikzset{circle with radius/.style = {shape = circle, inner sep = 0pt,
      outer sep = 0pt, minimum size = {2 * (#1)}}}
  \begin{tikzpicture}[scale = .5
    ]
  \coordinate (O) at (0, 0);

  \pgfmathsetmacro{\as}{3}
  \pgfmathsetmacro{\bs}{2.25}
  \pgfmathsetmacro{\c}{sqrt(\as^2 - \bs^2)}
  \pgfmathsetmacro{\al}{3.75}
  \pgfmathsetmacro{\bl}{2.9}
  \pgfmathsetmacro{\cl}{sqrt(\al^2 - \bl^2)}
  \pgfmathsetmacro{\xs}{abs(\c - \cl)}

  \coordinate (O) at (0, 0);

  \coordinate (F) at (\c, 0) {};

  \path[name path global = line1] (\c, 0) -- ++(60:{\as} and \bs);
  \path[name path global = line2] (\c, 0) -- ++(150:6cm);

    \draw[name path global = ell1] (O) ellipse
    (\as cm and \bs cm);

    \draw[name path global = ell2] (-\xs, 0)
    ellipse (\al cm and \bl cm);

  \path[name intersections = {of = line1 and ell1, by = P1}];
  \coordinate (A) at (P1) {};

  \path[name intersections = {of = line2 and ell2, by = P2}];
  \coordinate (B) at (P2) {};
  \begin{scope}[declare function = {doubleA = 5.8cm;}]
    \clip ($(A.center) + (1, 0)$) rectangle ($(B.center) + (0, 1)$);
    \begin{pgfinterruptboundingbox}
      \path let
      \p1 = ($(A) - (F)$),
      \p2 = ($(B) - (F)$),
      \n1 = {veclen(\x1, \y1)},
      \n2 = {veclen(\x2, \y2)}
      in
      (A) node[name path global = aCircle, circle with radius = doubleA-\n1]
      {}
      (B) node[name path global = bCircle, circle with radius = doubleA-\n2]
      {}
      (F) node[name path global = fCircle,
      circle with radius = .5 * doubleA] {};

      \tikzset{name intersections = {of = aCircle and bCircle, name = F'} }
      \foreach \solA in {2} {
        \path ($(F)!.5!(F'-\solA)$) coordinate (C'-\solA)
        ($(C'-\solA)!doubleA/2!(F)$) coordinate (xDir-\solA)
        (F'-\solA) node[name path global/.expanded = f'Circle-\solA,
        circle with radius = .5 * doubleA] {};
      }                         %!?                                                 
      \foreach \solA in {2} { %!?                                                   
        \path[name intersections = {of = fCircle and f'Circle-\solA,
          by = {yDir-\solA}}]
        ($(xDir-\solA)-(C'-\solA)$) coordinate (xDir'-\solA)
        ($(yDir-\solA)-(C'-\solA)$) coordinate (yDir'-\solA)
        ;
      }
    \end{pgfinterruptboundingbox}
    \foreach \solA in {2}
    \draw[x = (xDir'-\solA), y = (yDir'-\solA),
    name path global = traj]
    (C'-\solA) circle [radius = 1];
  \end{scope}
\end{tikzpicture}
\end{document}

不进行缩放:

在此处输入图片描述

缩放后:

在此处输入图片描述

有没有办法我可以扩展这个tikzpicture环境?


编辑2:

由于我只生成了 MWE,修复代码中的问题只会引发另一个无法预见的问题。因此,我发布了整个代码以及transform shape它带来的新问题。

根据 Peter 和 Qrrbrbirlbel 的建议,我能够解决缩放问题,但又出现了一个新问题(见下图):

在此处输入图片描述

1 不应该颠倒,那些节点和线不应该位于它们显示的位置。为什么会transform shape导致这个问题?

我刚刚在这里读了 Andrew Stacey 的帖子如何缩放包含文本的 tikzpicture?。他谈到将对transform shape节点应用旋转。

所以我尝试添加:

\tikzset{global scale/.style={
    scale=#1,
    every node/.style={scale=#1}
  }
}

按照安德鲁的建议将上面的代码添加到图片中,但没有任何改变。

我添加了非 MWE 的代码,因为没有 MWE 代码在这里没有帮助。这是因为当我实施一项更改时,其他内容受到了影响。因此,提供帮助的人不知道代码中还发生了什么。

\documentclass[convert = false]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, intersections, backgrounds, decorations.markings, arrows}
\begin{document}
\begin{tikzpicture}[line join = round, line cap = round, >=triangle 45,
    every label/.append style = {font = \scriptsize},
    dot/.style = {inner sep = +0pt, shape = circle,
      draw = black, label = {#1}},
    small dot/.style = {minimum size = .05cm, dot = {#1}},
    big dot/.style = {minimum size = .1cm, dot = {#1}},
    transform shape, scale = .75
    ]
    \tikzset{circle with radius/.style = {shape = circle, inner sep = 0pt,
        outer sep = 0pt, minimum size = {2 * (#1)}
      }
    }
    \tikzset{global scale/.style = {
        scale = #1,
        every node/.style = {scale = #1}
      }
    }

    \coordinate (O) at (0, 0);

    \pgfmathsetmacro{\as}{3}
    \pgfmathsetmacro{\bs}{2.25}
    \pgfmathsetmacro{\c}{sqrt(\as^2 - \bs^2)}
    \pgfmathsetmacro{\al}{3.75}
    \pgfmathsetmacro{\bl}{2.9}
    \pgfmathsetmacro{\cl}{sqrt(\al^2 - \bl^2)}
    \pgfmathsetmacro{\xs}{abs(\c - \cl)}

    \coordinate (O) at (0, 0);

    \clip (-1, .25) rectangle (-6, 4);

    \node[fill = black, big dot = {below left: \(F\)}] (F) at (\c, 0) {};

    \path[name path global = line1] (\c, 0) -- ++(60:{\as} and \bs);
    \path[name path global = line2] (\c, 0) -- ++(150:6cm);

    \begin{scope}[decoration = {markings,
        mark = at position 0.25 with {\arrow{>}},
        mark = at position 0.375 with {\node[draw, shape = circle,
          inner sep = .04cm, fill = white, font = \tiny] {\(1\)};},
        mark = at position 0.75 with {\arrow{>}},
      } ]
      \draw[postaction = decorate, name path global = ell1, blue] (O) ellipse
      (\as cm and \bs cm);
    \end{scope}

    \begin{scope}[decoration = {markings,
        mark = at position 0.25 with {\arrow{>}},
        mark = at position 0.6 with {\node[draw, shape = circle,
          inner sep = .04cm, fill = white, font = \tiny] {\(2\)};},
        mark = at position 0.75 with {\arrow{>}},
      },
      on background layer                                                          
      ]
      \draw[postaction = decorate, name path global = ell2, red] (-\xs, 0)
      ellipse (\al cm and \bl cm);
    \end{scope}

    \path[name intersections = {of = line1 and ell1, by = P1}];
    \node[fill = black, big dot = {right: \(A\)}] (A) at (P1) {};

    \path[name intersections = {of = line2 and ell2, by = P2}];
    \node[fill = black, big dot = {above: \(B\)}] (B) at (P2) {};

    \draw[blue] (F) -- (A);
    \draw[red] (F) -- (B) node[font = \scriptsize, fill = white,
    inner sep = 0cm, pos = .5] {\(r_B\)};

    \begin{scope}[on background layer]                                              
      \draw[dashed, -latex] ($(-\al , 0) - (1, 0)$) -- ($(\al, 0) + (.5, 0)$)
      coordinate (P3);
      \draw[dashed, -latex] ($(F) - (0, 3)$) -- ($(F) + (0, 3)$);
    \end{scope}

    \begin{scope}[declare function = {doubleA = 5.8cm;},
      decoration = {markings,
        mark = at position 0.175 with {\arrow{>}},
        mark = at position 0.225 with {\node[draw, shape = circle,
          inner sep = .04cm, fill = white, font = \tiny] {\(3\)};}
      } ]
      \clip ($(A.center) + (1, 0)$) rectangle ($(B.center) + (0, 1)$);
      \begin{pgfinterruptboundingbox}
        \path let
          \p1 = ($(A) - (F)$),
          \p2 = ($(B) - (F)$),
          \n1 = {veclen(\x1, \y1)},
          \n2 = {veclen(\x2, \y2)}
        in
        (A) node[name path global = aCircle, circle with radius = doubleA-\n1]
        {}
        (B) node[name path global = bCircle, circle with radius = doubleA-\n2]
        {}
        (F) node[name path global = fCircle,
        circle with radius = .5 * doubleA] {};

        \tikzset{name intersections = {of = aCircle and bCircle, name = F'} }
        \foreach \solA in {2} {
          \path ($(F)!.5!(F'-\solA)$) coordinate (C'-\solA)
          ($(C'-\solA)!doubleA/2!(F)$) coordinate (xDir-\solA)
          (F'-\solA) node[name path global/.expanded = f'Circle-\solA,
          circle with radius = .5 * doubleA] {};
        }                         %!?                                                
        \foreach \solA in {2} { %!?                                                  
          \path[name intersections = {of = fCircle and f'Circle-\solA,               
            by = {yDir-\solA}}]                                                      
          ($(xDir-\solA)-(C'-\solA)$) coordinate (xDir'-\solA)                       
          ($(yDir-\solA)-(C'-\solA)$) coordinate (yDir'-\solA)                       
          ;                                                                          
        }                                                                            
      \end{pgfinterruptboundingbox}     
      \foreach \solA in {2}                                                          
      \draw[x = (xDir'-\solA), y = (yDir'-\solA), postaction = decorate,             
      name path global = traj]                                                       
      (C'-\solA) circle [radius = 1];                                                
    \end{scope}                                                                 

    \draw[on background layer, red] let                                              
      \p0 = (F),                                                                     
      \p1 = (B),                                                                     
      \p2 = (P3),                                                                    
      \n1 = {atan2(\x1 - \x0, \y1 - \y0)},                                           
      \n2 = {atan2(\x2 - \x0, \y2 - \y0)},                                           
      \n3 = {.75cm},                                                                 
      \n4 = {(\n2 + \n1) / 2}                                                        
    in (F) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2]          
    node[font = \tiny, fill = white, inner sep = 0cm] at                             
    ([shift = (F)] \n4:\n3) {\(\nu_B\)};                                             

    \draw[blue] let                                                                  
      \p0 = (F),                                                                     
      \p1 = (A),                                                                     
      \p2 = (P3),                                                                    
      \n1 = {atan2(\x1 - \x0, \y1 - \y0)},                                           
      \n2 = {atan2(\x2 - \x0, \y2 - \y0)},                                           
      \n3 = {.5cm},                                                                  
      \n4 = {(\n2 + \n1) / 2}                                                        
    in (F) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2]          
    node[font = \tiny, fill = white, inner sep = 0cm] at                             
    ([shift = (F)] \n4:.75cm) {\(\nu_A\)};                                                                    

    \path[name path = circ] (B) circle [radius = 1bp];                                                                                                                    
    \draw[name intersections = {of = circ and traj}, -latex] (B) --                  
    ($(intersection-1)!1.25cm!(intersection-2)$) node[pos = .4, font = \tiny,        
    below, fill = white, inner sep = 0cm] {\(\mathbf{v}_1\)} coordinate (P3);        
    \draw[name intersections = {of = circ and ell2}, -latex, red] (B) --             
    ($(intersection-1)!2cm!(intersection-2)$) node[pos = .5, font = \tiny,           
    above] {\(\mathbf{v}_2\)} coordinate (P4);                                       
    \draw[-latex, name path = line3] (P3) -- (P4) node[pos = .5, font = \tiny,       
    fill = white, inner sep = 0cm] {\(\Delta\mathbf{v}\)};                           
    \draw[name path = line4] (B) -- ($(B)!2.1cm!-90:(F)$) coordinate (P5);           

    \path[name path = circ2] (P3) circle [radius = 1bp];                             
    \path[name intersections = {of = circ2 and line3}, name path = line5]            
    (P3) -- ($(intersection-1)!2cm!(P3)$);                                           
    \path[name intersections = {of = line5 and line4, by = P6}];                     

    \draw[dotted] (P3) -- (P6);                                                      

    \path[name intersections = {of = circ and traj}] (B) --                          
    ($(intersection-1)!1.5cm!(intersection-2)$) coordinate (P7);                     

    \draw (P3) -- (P7);                                                              

    \path[name intersections = {of = circ and ell2}] (B) --                          
    ($(intersection-1)!2.5cm!(intersection-2)$) coordinate (P8);                     

    \draw (P4) -- (P8);                                                              

    \draw let                                                                        
      \p0 = (B),                                                                     
      \p1 = (P5),                                                                    
      \p2 = (P3),                                                                    
      \n1 = {atan2(\x1 - \x0, \y1 - \y0)},                                           
      \n2 = {atan2(\x2 - \x0, \y2 - \y0)},
      \n3 = {1.4cm},
      \n4 = {(\n2 + \n1) / 2}
    in (B) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2]
    coordinate (P9) at ([shift = (B)] \n4:\n3);

    \draw (P9) .. controls ($(P9) - (.15, .15)$) .. ($($(P9) - (.15, .15)$) +        
    (.25, -.3)$) node[font = \tiny, fill = white, inner sep = 0cm]
    {\(\gamma_1\)};

    \draw[-latex] let
      \p0 = (B),
      \p1 = (P5),
      \p2 = (P8),
      \n1 = {atan2(\x1 - \x0, \y1 - \y0)},
      \n2 = {atan2(\x2 - \x0, \y2 - \y0)},
      \n3 = {2.1cm},
      \n4 = {(\n2 + \n1) / 2}
    in (B) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2]
    node[fill = white, inner sep = 0cm, font = \tiny] at ([shift = (B)]
    \n4:\n3) {\(\gamma_2\)};

    \draw let
      \p0 = (B),
      \p1 = (P3),
      \p2 = (P4),
      \n1 = {atan2(\x1 - \x0, \y1 - \y0)},
      \n2 = {atan2(\x2 - \x0, \y2 - \y0)},
      \n3 = {1cm},
      \n4 = {(\n1 + \n2) / 2}
    in (B) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2]
    node[fill = white, inner sep = 0cm, font = \tiny] at
    ([shift = (B)] \n4:\n3) {\(\Delta\gamma\)} coordinate (DG);

    \begin{scope}[on background layer]
      \draw[-latex] let
        \p0 = (P6),
        \p1 = (P5),
        \p2 = (P4),
        \n1 = {atan2(\x1 - \x0, \y1 - \y0)},
        \n2 = {atan2(\x2 - \x0, \y2 - \y0) - 360},
        \n3 = {.75cm},
        \n4 = {(\n2 + \n1) / 2}
      in (P6) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2]
      node[fill = white, inner sep = 0cm, font = \tiny] at ([shift = (P6)]
      \n4:\n3) {\(\phi\)};
  \end{scope}                                                                    
\end{tikzpicture}
\end{document}

相关内容