画出一张剪成盒子的纸张

画出一张剪成盒子的纸张

因此,我尝试在 tikz 中重新创建下面的两幅图像。第一幅图像很简单,我还没有添加标签等,但这很容易。

但是,我对第二个感到困惑。我怎样才能使 3D 框插图和平面插图相同。例如,如果我增加蓝色问号块的大小,3D 框应该会变高,而较小的蓝色问号块应该会减小尺寸。关于如何进行,有什么想法吗?

在此处输入图片描述

这是我的尝试

在此处输入图片描述

和代码

\documentclass{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}

\begin{document}
\newcommand\dashrec[3]{%
    \draw[draw=black,dashed,fill=blue,fill opacity=0.1] 
        (#1) rectangle ++(#2, #3) node[fill opacity=1, pos=.5] {?};%
}
\def\height{3}\def\width{4}\def\x{1}
\begin{tikzpicture}
  \coordinate (A) at (0,0);
  \coordinate (B) at (\width,0);
  \coordinate (C) at (\width,\height);
  \coordinate (D) at (0,\height);
 
  \dashrec{A}{ \x}{ \x}
  \dashrec{B}{-\x}{ \x}
  \dashrec{C}{-\x}{-\x}
  \dashrec{D}{ \x}{-\x}
  
  \draw[draw=white,ultra thick] (A) rectangle (C);
  \draw[black] (A) rectangle (C);
\end{tikzpicture}\hspace{2cm}
\begin{tikzpicture}
  \def\slantx{-1}
  \def\slanty{1}
  \coordinate (A) at (0,0);
  \coordinate (B) at (\width,\slanty);
  \coordinate (C) at (\width+\slantx,\height+\slanty);
  \coordinate (D) at (\slantx,\height);

  \draw (A.center) -- (B.center) -- (C.center) -- (D.center) -- cycle;
\end{tikzpicture}
\end{document}

答案1

您应该使用 tikz 3d 库。使用 3d 时,两种绘图几乎相同。好吧,3d 有第三个坐标和几条线,但仅此而已。

\documentclass {standalone}
\usepackage    {tikz}
\usetikzlibrary{3d}

\begin{document}
\def\width {5}
\def\height{4}
\def\x     {0.8}

\begin{tikzpicture}[line cap=round, line join=round]
\foreach\i/\j in {0/0, 0/\height-\x, \width-\x/0, \width-\x/\height-\x}
  {
    \draw[dashed,fill=blue!15] (\i,\j) rectangle (\i+\x,\j+\x);
    \node at (\i+0.5*\x,\j+0.5*\x) {?};
  }
  \draw[thick] (0,0) rectangle (\width,\height);
  \draw (\x,\x) rectangle (\width-\x,\height-\x);
\end{tikzpicture}

\begin{tikzpicture}[scale=1.25,x={(-0.9220cm,-0.1626cm)},y={(0.3872cm,-0.3872cm)},z={(0cm,0.9076cm)},line cap=round,line join=round]
  \begin{scope}[canvas is xy plane at z=0]
    \foreach\i/\j in {0/0, 0/\height-\x, \width-\x/0, \width-\x/\height-\x}
    {
      \draw[dashed,fill=blue!15] (\i,\j) rectangle (\i+\x,\j+\x);
    }
    \draw (0,0) rectangle (\width,\height);
    \draw[thick] (\x,\x) rectangle (\width-\x,\height-\x);
  \end{scope}
  \begin{scope}[canvas is xy plane at z=\x]
    \draw[thick] (\x,\x) rectangle (\width-\x,\height-\x);
  \end{scope}
  \foreach\i/\j in {\x/\x, \x/\height-\x, \width-\x/\x, \width-\x/\height-\x}
  {
    \draw[thick] (\i,\j,0) -- (\i,\j,\x);
  }
\end{tikzpicture}
\end{document}

当然,如果你改变参数\width\height或者\x两个图形都会相应改变。它看起来是这样的: 在此处输入图片描述

相关内容