将 tikz 图拟合到 ZY 平面画布

将 tikz 图拟合到 ZY 平面画布

我学会了如何在 ZY 平面上绘制事物,但我并不完全了解它的工作原理。下面是我的代码:

\documentclass{standalone}

\usepackage{tikzducks}
\usetikzlibrary{3d,graphs,graphdrawing}
\usegdlibrary{trees}

\begin{document}

  \begin{tikzpicture}
    \newcommand{\planes}{\fill[gray!20!white,opacity=0.9] (-0.1,-0.1) rectangle (2.4,2.4);}
    \newcommand{\hooks}{\draw[blue, rounded corners=3pt, line width=1pt] (-0.1,-0.1) rectangle (2.4,2.4);}
    \newcommand{\graphA}{\graph [nodes={circle, inner sep=0pt, minimum size=2mm, fill, as=}]{
    a -- { b -- c -- { d -- e, f -- { g, h }}, i -- j -- k[second] }
    };}
    \begin{scope}[canvas is zy plane at x=0]
      \hooks
    \end{scope}
    \begin{scope}[canvas is zy plane at x=0.8]
      \planes
      \duck
    \end{scope}
    \begin{scope}[canvas is zy plane at x=1.6]
      \hooks
    \end{scope}
    \begin{scope}[canvas is zy plane at x=2.4]
      \planes
      \graphA 
    \end{scope}
  \end{tikzpicture}

\end{document}

输出:

在此处输入图片描述

tikz duck 可以自动适应 ZY 平面画布,但我自定义的图形却不能。为什么会这样?如何让图形适应 ZY 平面画布?

答案1

由于您绘制的是节点,因此默认情况下它们不会变换其图形,因为只有它们的位置会受到影响,因此如果它们这样做,您必须指示变换形状修改器,正如您所见,这也会影响节点。以下是一些示例,并进行了一些安排,以便可以阅读。

结果:

在此处输入图片描述

梅威瑟:

%Compiled using LuaLatex, needeed for graphs,graphdrawing 
\documentclass[border=3.14pt]{standalone}
\usepackage{tikzducks}
\usetikzlibrary{3d,graphs,graphdrawing}
\usetikzlibrary{trees}

\begin{document}
    
    \begin{tikzpicture}
        \newcommand{\planes}{\fill[gray!20!white,opacity=0.9] (-0.1,-0.1) rectangle (2.4,2.4);}
        \newcommand{\hooks}{\draw[blue, rounded corners=3pt, line width=1pt] (-0.1,-0.1) rectangle (2.4,2.4);}
        \newcommand{\graphA}{\graph[nodes={circle, inner sep=0pt, minimum size=2mm, fill}]{
                a -- { b -- c -- { d -- e, f -- { g, h }}, i -- j -- k }
            };}
        \begin{scope}[canvas is zy plane at x=0]
            \hooks
        \end{scope}
        \begin{scope}[canvas is zy plane at x=0.8]
            \planes
            \duck
        \end{scope}
        \begin{scope}[canvas is zy plane at x=1.6]
            \hooks
        \end{scope}
        \begin{scope}[canvas is zy plane at x=2.4, transform shape]
            \planes
            \begin{scope}[yshift=2cm,scale=0.5]
                \graphA 
            \end{scope}
            
        \end{scope}
        \begin{scope}[canvas is zy plane at x=3.2]
            \hooks
        \end{scope}
        \begin{scope}[canvas is zy plane at x=4]
            \planes
            \draw[](1,1) node[label=90:default] {\includegraphics[height=1cm]{example-image-a}};
        \end{scope}
        \begin{scope}[canvas is zy plane at x=4.8]
            \hooks
        \end{scope}
        \begin{scope}[canvas is zy plane at x=5.6,transform shape]
            \planes
            \draw[](1,1) node[label=transform shape]{\includegraphics[height=1cm]{example-image-b}};
        \end{scope}
        \begin{scope}[canvas is zy plane at x=6.4]
            \hooks
        \end{scope}
        \begin{scope}[canvas is zy plane at x=7.7,transform shape]
            \planes
            \draw[](1,1) node[label={[xscale=-1]90:xscale=-1},xscale=-1]{\includegraphics[height=1cm]{example-image-c}};
        \end{scope}
        
    \end{tikzpicture}
    
\end{document}

答案2

似乎是默认的图形布局导致了这个问题,我添加了binary tree layout图形选项,解决了这个问题。我进一步将图形包装在环境中,通过设置、scope和 来重新缩放并将其移动到灰色平面的中心scalexshiftyshift

\documentclass{standalone}

\usepackage{tikzducks}
\usetikzlibrary{3d,graphs,graphdrawing}
\usegdlibrary{trees}

\begin{document}

  \begin{tikzpicture}
    \newcommand{\planes}{\fill[gray!20!white,opacity=0.9] (-0.1,-0.1) rectangle (2.4,2.4);}
    \newcommand{\hooks}{\draw[blue, rounded corners=3pt, line width=1pt] (-0.1,-0.1) rectangle (2.4,2.4);}
    \newcommand{\graphA}{
        \begin{scope}[scale=0.4,xshift=40,yshift=20]{
            \graph[binary tree layout, nodes={circle, inner sep=0pt, minimum size=2mm, fill, as=}, grow=up]{
            a -- { b -- c -- { d -- e, f -- { g, h }}, i -- j -- k[second] }
            };
        }
        \end{scope}
    }
    \begin{scope}[canvas is zy plane at x=0]
      \hooks
    \end{scope}
    \begin{scope}[canvas is zy plane at x=0.8]
      \planes
      \duck
    \end{scope}
    \begin{scope}[canvas is zy plane at x=1.6]
      \hooks
    \end{scope}
    \begin{scope}[canvas is zy plane at x=2.4]
      \planes
      \graphA 
    \end{scope}
  \end{tikzpicture}

\end{document}

输出:

在此处输入图片描述

相关内容