4

The idea is to create an arrow between the upper surface of the first cube and the upper face of the second cube indicating a multiplication by 2, and an arrow of the upper side of the second cube between the upper face of the third cube showing the addition of 3.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{3d}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture}
\tikzset{xzplane/.style={canvas is xz plane at y=#1, thick,shading=ball,ball color=red,draw=black}};
\tikzset{yzplane/.style={canvas is yz plane at x=#1,thick,shading=ball, ball color=red,draw=black}};
\tikzset{xyplane/.style={canvas is xy plane at z=#1,thick,shading=ball,ball color=red,draw=black}};

\draw[xzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[yzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] node[white] at (1,1){\Large 7};
\draw[xyplane=2] node[below=0.25cm] at (1,0){\Large $X$};

\begin{scope}[shift={(4 cm,0 cm)}]
\draw[xzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[yzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] node[white] at (1,1){\Large 14};
\draw[xyplane=2] node[below=0.25cm] at (1,0) {\Large $X$};
\end{scope}

\begin{scope}[shift={(8 cm,0 cm)}]
\draw[xzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[yzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] node[white] at (1,1){\Large 17};
\draw[xyplane=2] node[below=0.25cm] at (1,0){\Large $X$};
\end{scope}
\end{tikzpicture}
\end{document}

enter image description here

3 Answers 3

4

You can also use pic

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{3d}
\usetikzlibrary{positioning}
\tikzset{
fleche/.style={thick,>=stealth,->},
%bulle/.style={circle,draw,thick},
pics/.cd,
myplane/.style args={#1#2}{
code={
\draw[xzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[yzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] node[white,font=\Large] at (1,1){#1};
\draw[xyplane=2] node[below=0.25cm,font=\Large] at (1,0){$#2$};
\coordinate  (-top) at (0.75,1.85);
}},
}
\begin{document}

\begin{tikzpicture}
\tikzset{xzplane/.style={canvas is xz plane at y=#1, thick,shading=ball,ball color=red,draw=black}};
\tikzset{yzplane/.style={canvas is yz plane at x=#1,thick,shading=ball, ball color=red,draw=black}};
\tikzset{xyplane/.style={canvas is xy plane at z=#1,thick,shading=ball,ball color=red,draw=black}};

\pic (first) {myplane={7}{X}};
\pic (second) at (4,0) {myplane={14}{X}};
\pic (third) at (8,0) {myplane={17}{X}};

\draw[thick,fleche] ([xshift=3mm]first-top) to[bend left=50,->] node[above]{$           ×           2$} ([xshift=-3mm]second-top);
\draw[thick,fleche] ([xshift=3mm]second-top) to[bend left=50,->] node[above]{$       +       3$} ([xshift=-3mm]third-top);

\end{tikzpicture}
\end{document}

enter image description here

1
  • @ Harish Thank you, I am impressed by the possibilities of TikZ because I only use PSTricks or Metapost. I must say that I have a little trouble with the syntax of TikZ. In addition, your code compiles with ConTeXt.
    – Fabrice
    Oct 29, 2014 at 10:20
5

In case you are doing more of these diagrams, I would use a package for the creation of commutative diagrams which makes the connection with arrows really easy.

Here is a version with use of which is highly compatible with all the TikZ you need:

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{3d}

\begin{document}
\tikzset{xzplane/.style={canvas is xz plane at y=#1, thick,shading=ball,ball color=red,draw=black}}
\tikzset{yzplane/.style={canvas is yz plane at x=#1,thick,shading=ball, ball color=red,draw=black}}
\tikzset{xyplane/.style={canvas is xy plane at z=#1,thick,shading=ball,ball color=red,draw=black}}
\[\begin{tikzcd}
\tikz{\draw[xzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[yzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] node[white] at (1,1){\Large 7};
\draw[xyplane=2] node[below=0.25cm] at (1,0){\Large $X$};}
\arrow[thick, bend left, start anchor = north, end anchor = north, shorten >=1mm]{r}[scale=2]{\cdot 2}
&\tikz{\draw[xzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[yzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] node[white] at (1,1){\Large 14};
\draw[xyplane=2] node[below=0.25cm] at (1,0) {\Large $X$};}
\arrow[thick, bend left, start anchor = north, end anchor = north, shorten <= 1mm]{r}[scale=2]{+ 3}
&\tikz{\draw[xzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[yzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] node[white] at (1,1){\Large 17};
\draw[xyplane=2] node[below=0.25cm] at (1,0){\Large $X$};}
\end{tikzcd}\]
\end{document} 

enter image description here

If you wanted to start the arrow on top of the upper surface, you can just shift a bit in direction south which could look like start anchor = {[yshift=-3ex]north}


Here is an example showing a 'more difficult' matrix and the possibility to define global options for labels and alike:

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{3d}

\begin{document}
\tikzset{xzplane/.style={canvas is xz plane at y=#1, thick,shading=ball,ball color=red,draw=black}}
\tikzset{yzplane/.style={canvas is yz plane at x=#1,thick,shading=ball, ball color=red,draw=black}}
\tikzset{xyplane/.style={canvas is xy plane at z=#1,thick,shading=ball,ball color=red,draw=black}}
\newcommand{\drawCube}[2]{\draw[xzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[yzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] node[white] at (1,1){\Large #1};
\draw[xyplane=2] node[below=0.25cm] at (1,0){\Large $#2$};}
\[\begin{tikzcd}[every label/.append style={scale=2}, every arrow/.append style = {thick, shorten <= 1mm, shorten >= 1mm}]
\tikz{\drawCube{7}{X}}
\arrow[bend left, start anchor ={[yshift=-3ex]north}, end anchor = {[yshift=-3ex]north}]{r}{\cdot 2}
& \tikz{\drawCube{14}{X}}
\arrow[bend left, start anchor ={[yshift=-3ex]north}, end anchor = {[yshift=-3ex]north}, shorten <= 1mm]{r}{+3}
& \tikz{\drawCube{17}{X}} \arrow[bend left, start anchor ={[xshift=-1em, yshift=+4ex]east}, end anchor = {[xshift=-1em, yshift=+4ex]east}]{d}{-7} & \\
& & \tikz{\drawCube{10}{Y}}\arrow[bend right, start anchor = south, end anchor = south, swap]{r}{\div 5}
& \tikz{\drawCube{2}{Z}}
\end{tikzcd}\]
\end{document}

enter image description here


Or even:

% arara: pdflatex

\documentclass{article}
\usepackage{tikz-cd}
\usetikzlibrary{3d}

\begin{document}
\tikzset{xzplane/.style={canvas is xz plane at y=#1, thick,shading=ball,ball color=red,draw=black}}
\tikzset{yzplane/.style={canvas is yz plane at x=#1,thick,shading=ball, ball color=red,draw=black}}
\tikzset{xyplane/.style={canvas is xy plane at z=#1,thick,shading=ball,ball color=red,draw=black}}
\newcommand{\drawCube}[2]{\draw[xzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[yzplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] (0,0)--(2,0)--(2,2)--(0,2) --cycle;
\draw[xyplane=2] node[white] at (1,1){\Large #1};
\draw[xyplane=2] node[below=0.25cm] at (1,0){\Large $#2$};}
\[\begin{tikzcd}[row sep = -22ex, column sep = 3.5em, every label/.append style={scale=2}, every arrow/.append style = {thick, shorten <= 1mm, shorten >= 1mm}] % adapt row and column sep to get your desired perspective view
&&\tikz{\drawCube{17}{X}} \arrow[bend left=50, start anchor ={[xshift=-1.5em, yshift=+4ex]east}, end anchor = {[xshift=-1.5em, yshift=+4ex]east}]{dddd}{-7} &\\
&\tikz{\drawCube{14}{X}}
\arrow[bend left, start anchor ={[yshift=-3ex]north}, end anchor = {[yshift=-3ex]north}, shorten <= 1mm]{ur}{+3}&&\\
\tikz{\drawCube{7}{X}}
\arrow[bend left, start anchor ={[yshift=-3ex]north}, end anchor = {[yshift=-3ex]north}]{ur}{\cdot 2}&&&\\
&&&\tikz{\drawCube{2}{Z}}\\
&&\tikz{\drawCube{10}{Y}}\arrow[bend right, start anchor = south, end anchor = {[xshift=-2em]south}, swap]{ur}{\div 5}&
\end{tikzcd}\]
\end{document}

enter image description here

5
  • @ LaRiFaRi Thank you, I started with TikZ, and I did not know this package. Initially, I wanted to do this :\begin{tikzpicture} \tikzstyle {bulle}=[circle,draw,thick] \tikzstyle{fleche}=[thick,>=stealth,->] \node(debut1) at (0,0) {$7$}; \node(debut3) at (4,0) {$14$}; \draw [fleche](debut1.north) to [bend left] (debut3.north); \node [bulle,fill=white] (debut6) at (2,0.75) {$\times 2$}; \end{tikzpicture}
    – Fabrice
    Oct 28, 2014 at 22:43
  • @ LaRiFaRi Your code does not compile with ConTeXt. There seems to be a problem with the package {tikz-cd}.
    – Fabrice
    Oct 29, 2014 at 10:24
  • @Fabrice Sorry, I never used ConTeXt. No idea about that.
    – LaRiFaRi
    Oct 29, 2014 at 11:22
  • 1
    @Fabrice if you replace all &'s by \pgfmatrixnextcell it should work.
    – Augusto
    Oct 31, 2014 at 1:14
  • @Forêncio Unfortunately, this does not work.
    – Fabrice
    Nov 1, 2014 at 9:06
5

As an alternative to all the "3d" stuff, here's an example just using slanting and scaling. Then nodes can be used for each side of the cube:

\documentclass[tikz, border=5]{standalone}
\usetikzlibrary{arrows.meta}
\tikzset{%
  cube join/.style={
    thick, -{Stealth}, 
  },
  cube face/.style={
    minimum size=1cm, outer sep=0pt,
    draw=white, thick, line join=round,
    shading=ball, ball color=red,
    text=white, font=\bfseries
  },    
  pics/cube/.style args={#1 with #2}{
  code={
    \node [cube face, label={[name=-label]below:#2}] (-front) {#1};
    \node [cube face] (-top)  at (-front.north west) [anchor=south west, xslant=1, yscale=1/3] {};
    \node [cube face] (-side) at (-front.south east) [anchor=south west, yslant=1, xscale=1/3] {};
   }}
}
\begin{document}
\begin{tikzpicture}
\pic  (eight)   at (-1, 1) {cube=8  with $A$}; 
\pic  (fifteen) at ( 1, 1) {cube=15 with $B$};
\pic  (three)   at ( 1,-1) {cube=3  with $C$};
\pic  (two)     at (-1,-1) {cube=2  with $D$};
\draw [cube join] (eight-top.center)    to [bend left] node [midway, above] {$+7$}      (fifteen-top.center);
\draw [cube join] (fifteen-side.center) to [bend left] node [midway, right] {$\div5$}   (three-side.center);
\draw [cube join] (three-label.south)   to [bend left] node [midway, below] {$-1$}      (two-label.south);
\draw [cube join] (two-front.west)      to [bend left] node [midway, left]  {$\times4$} (eight-front.west);
\end{tikzpicture}
\end{document}

enter image description here

4
  • @ Mark Thank you, I am impressed by the possibilities of TikZ because I only use PSTricks or Metapost. I must say that I have a little trouble with the syntax of TikZ. In addition, your code compiles with ConTeXt.
    – Fabrice
    Oct 29, 2014 at 10:21
  • @MarkI would like to add an argument to be able to choose the color of the faces.
    – Fabrice
    Nov 1, 2014 at 9:07
  • 1
    @Fabrice you can just say \pic [cube face/.append style={ball color=blue}] (-1, 1) {cube=8 with $A$};. Alternatively you could tie that up in a key \tikzset{face color/.style={cube face/.append style={ball color=#1}}}. Is that sufficient? Nov 1, 2014 at 12:35
  • @MarkThank you. I tested the second method, it works. Maybe my code is not as "clean" as yours !
    – Fabrice
    Nov 2, 2014 at 12:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .