立方体的解剖

立方体的解剖

我从原始长方体进行切割,生成四个较小的长方体,每个长方体有三种不同的方法。第一种是沿着任意两条边切两刀,如图所示。我需要再画两个图:第二种是沿着一个面的长度平行切三刀,得到四个小长方体,不一定。第三种是沿着宽度平行切三刀,得到四个小长方体。

因此我需要帮助绘制另外两幅插图。

每种情况下四块碎片的体积之和等于原始长方体的体积。

\documentclass[tikz, border=5pt]{standalone}
    \usepackage{tikz,pgfkeys}
    \makeatletter
    \def\pgfutil@gobble#1{}
    \pgfkeys{/handlers/.unknown to list/.code=%
      \let#1\pgfutil@gobble
      \pgfkeysalso{% or \pgfkeys{\pgfkeyscurrentpath/.cd,
        .unknown/.code=% how to handle the difference between 'key' and 'key=value'?
          \ifx\pgfkeyscurrentvalue\pgfkeysnovalue
            \let\pgfkeys@temp\pgfkeyscurrentname
          \else
            \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\pgfkeys@temp\expandafter\expandafter\expandafter{\expandafter\pgfkeyscurrentname\expandafter=\expandafter{\pgfkeyscurrentvalue}}%
          \fi
          \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter#1\expandafter,\pgfkeys@temp},%
         .@clear list/.code=\let#1\pgfutil@gobble}%
    }
    \makeatother

    \pgfkeys{
     /cuboid/.is family, /cuboid,
     depth/.estore in = \cuboidz,
     width/.estore in = \cuboidx,
     height/.estore in = \cuboidy,
     front/.estore in = \cuboidzStyle,
     side/.estore in = \cuboidxStyle,
     top/.estore in = \cuboidyStyle,
     .unknown to list = \cuboidOptions,
     default/.style = {width=1, height=1, depth=1, front=, side=, top=, draw},
    }

    \newcommand{\cuboid}[2][]{
      \pgfkeys{/cuboid, default, #1}%
      \begingroup
        \edef\x{%
          \endgroup
          \noexpand\begin{scope}[shift={#2}, join=bevel, \cuboidOptions]
            \noexpand\draw[fill,\cuboidyStyle] (0,\cuboidy,0) -- (\cuboidx,\cuboidy,0) -- (\cuboidx,\cuboidy,\cuboidz) -- (0,\cuboidy,\cuboidz) -- cycle;
            \noexpand\draw[fill,\cuboidxStyle] (\cuboidx,0,0) -- (\cuboidx,\cuboidy,0) -- (\cuboidx,\cuboidy,\cuboidz) -- (\cuboidx,0,\cuboidz) -- cycle;
            \noexpand\draw[fill,\cuboidzStyle] (0,0,\cuboidz) -- (\cuboidx,0,\cuboidz) -- (\cuboidx,\cuboidy,\cuboidz) -- (0,\cuboidy,\cuboidz) -- cycle;
          \noexpand\end{scope}
          \noexpand\pgfkeys{/cuboid/.@clear list}
        }%
        \x
    }

    \begin{document}
    \tikzstyle{interior}=[fill=blue!50]
    \begin{tikzpicture}[scale=.7, fill=blue!60, z={(225:.8)}, x={(-10:1)}]
      \cuboid[front=interior, side=interior]{(0,1.5,0)} \cuboid[front=interior, width=2]{(1.25,1.5,0)}
      \cuboid[side=interior]{(0,1.5,1.5)} \cuboid[width=2, front=]{(1.25,1.5,1.5)}
    \end{tikzpicture}
    \end{document}

答案1

虽然原帖作者没有礼貌地这么说,但这段代码可能是根据 Emma 在https://tex.stackexchange.com/a/334421/。 谢谢Bobyandbob 用于追踪问题中应该指定的来源

据我所知,你只需要应用适当的选项来产生你想要的划分。然而,我担心这意味着我一定错过了什么。

\documentclass[tikz, border=5pt]{standalone}
\usepackage{tikz,pgfkeys}
\makeatletter
\def\pgfutil@gobble#1{}
\pgfkeys{/handlers/.unknown to list/.code=%
  \let#1\pgfutil@gobble
  \pgfkeysalso{% or \pgfkeys{\pgfkeyscurrentpath/.cd,
    .unknown/.code=% how to handle the difference between 'key' and 'key=value'?
    \ifx\pgfkeyscurrentvalue\pgfkeysnovalue
    \let\pgfkeys@temp\pgfkeyscurrentname
    \else
    \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter\pgfkeys@temp\expandafter\expandafter\expandafter{\expandafter\pgfkeyscurrentname\expandafter=\expandafter{\pgfkeyscurrentvalue}}%
    \fi
    \expandafter\expandafter\expandafter\def\expandafter\expandafter\expandafter#1\expandafter\expandafter\expandafter{\expandafter#1\expandafter,\pgfkeys@temp},%
    .@clear list/.code=\let#1\pgfutil@gobble}%
}
\makeatother

\pgfkeys{
  /cuboid/.is family, /cuboid,
  depth/.estore in = \cuboidz,
  width/.estore in = \cuboidx,
  height/.estore in = \cuboidy,
  front/.estore in = \cuboidzStyle,
  side/.estore in = \cuboidxStyle,
  top/.estore in = \cuboidyStyle,
  .unknown to list = \cuboidOptions,
  default/.style = {width=1, height=1, depth=1, front=, side=, top=, draw},
}

\newcommand{\cuboid}[2][]{%
  \pgfkeys{/cuboid, default, #1}%
  \begingroup
  \edef\x{%
    \endgroup
    \noexpand\begin{scope}[shift={#2}, join=bevel, \cuboidOptions]
      \noexpand\draw[fill,\cuboidyStyle] (0,\cuboidy,0) -- (\cuboidx,\cuboidy,0) -- (\cuboidx,\cuboidy,\cuboidz) -- (0,\cuboidy,\cuboidz) -- cycle;
      \noexpand\draw[fill,\cuboidxStyle] (\cuboidx,0,0) -- (\cuboidx,\cuboidy,0) -- (\cuboidx,\cuboidy,\cuboidz) -- (\cuboidx,0,\cuboidz) -- cycle;
      \noexpand\draw[fill,\cuboidzStyle] (0,0,\cuboidz) -- (\cuboidx,0,\cuboidz) -- (\cuboidx,\cuboidy,\cuboidz) -- (0,\cuboidy,\cuboidz) -- cycle;
      \noexpand\end{scope}
    \noexpand\pgfkeys{/cuboid/.@clear list}
  }%
  \x
}

\tikzset{% \tikzstyle is deprecated
  interior/.style={fill=cuboid colour!50},
  cuboid aspect/.style={z={(225:.8)}, x={(-10:1)}},
  cuboid colour/.code={
    \colorlet{cuboid colour}{#1}
  },
  cuboid colour=blue!60,
  /cuboid/default/.append style={fill=cuboid colour},
}

\begin{document}
\begin{tikzpicture}[cuboid aspect]
  \begin{scope}[cuboid colour=blue!60]
    \cuboid[front=interior, side=interior]{(0,1.5,0)} 
    \cuboid[front=interior, width=2]{(1.25,1.5,0)}
    \cuboid[side=interior]{(0,1.5,1.5)} 
    \cuboid[width=2, front=]{(1.25,1.5,1.5)}
  \end{scope}
  \begin{scope}[cuboid colour=green!75!black!60]
    \cuboid [front=interior, width=3, depth=.5] {(0,-1.5,0)}
    \cuboid [front=interior, width=3, depth=.5] {(-0.5,-2.25,0)}
    \cuboid [front=interior, width=3, depth=.5] {(-1,-3,0)}
    \cuboid [width=3, depth=.5] {(-1.5,-3.75,0)}
  \end{scope}
  \begin{scope}[cuboid colour=magenta!60]
    \cuboid [side=interior, width=.75, depth=2] {(0,-5.5,0)}
    \cuboid [side=interior, width=.75, depth=2] {(1,-5.5,0)}
    \cuboid [side=interior, width=.75, depth=2] {(2,-5.5,0)}
    \cuboid [width=.75, depth=2] {(3,-5.5,0)}
  \end{scope}
\end{tikzpicture}
\end{document}

3个部门

相关内容