1

From an original cuboid, I perform cuts to generate four smaller cuboids each, in three different ways. The first is to make two cuts along either two sides, as shown. I need to draw two more illustrations: the second is to make three parallel cuts along the length of one faces to result into four small cuboids, not necessarily. The third is make three cuts parallel to the width to produce four smaller cuboids.

So I need help with two more illustrations.

The sum of volumes of four pieces in each case is equal to the volume of the original cuboid.

\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}
  • Could you add some more details? Do you want to cut one cube several time from different sides? The third cut should be done horizonal? - Could you provide an image how it should look like (at the end)? – Bobyandbob Feb 25 '18 at 13:50
  • ok, I will add an image. – Thumbolt Feb 25 '18 at 14:18
  • The first case is to make two cuts that are perpendicular to each other, each is parallel to the width, length of the top surface. The second case is to make three parallel cuts each cut is parallel to the width of the top face. The third case is similarly to the second case but cuts parallel to the length of the top face. – Thumbolt Feb 25 '18 at 14:44
  • If this code is derived from elsewhere, can you please attribute it and provide a link? – cfr Feb 25 '18 at 21:46
  • 1
    I think the reference is draw a bundle of rectangular blocks. – Bobyandbob Feb 25 '18 at 21:50
2

Although the OP didn't have the courtesy to say so, this code is probably adapted from that posted by Emma at https://tex.stackexchange.com/a/334421/. Thanks to Bobyandbob for tracking down the source which should have been specified in the question.

As far as I can tell, you just need to apply appropriate options to produce the divisions you want. However, I worry that this means I must be missing something.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.