Stacking 3D Cubes with SpacingHow to draw a cube as the following?I want to draw cubes stacked on top of each other. Help?Accessing individual table elements with pgfplots?How do I change properties of a cube in TikZ?How do I fix spacing on paths for a nested tikz flowchart?some problems about cubes and tikz pictureHow Can I draw a cube of cubes efficiently?Compound Pathway Problem with holesWord Vector with the help of TikzSpacing between branches of treesDrawing 3d grids (cubes)How to draw cubes in a 3 dimensional plane

Exclude loop* snap devices from lsblk output?

On studying Computer Science vs. Software Engineering to become a proficient coder

Why does my circuit work on a breadboard, but not on a perfboard? I am new to soldering

Is there a spell to protect inanimate objects?

Two researchers want to work on the same extension to my paper. Who to help?

As programers say: Strive to be lazy

How to slow yourself down (for playing nice with others)

Reaction of borax with NaOH

Why can't RGB or bicolour LEDs produce a decent yellow?

How can this pool heater gas line be disconnected?

How to cope with regret and shame about not fully utilizing opportunities during PhD?

Proof that the inverse image of a single element is a discrete space

Is taking modulus on both sides of an equation valid?

Ex-manager wants to stay in touch, I don't want to

What are the components of a legend (in the sense of a tale, not a figure legend)?

Why not just directly invest in the holdings of an ETF?

Exception propagation: When should I catch exceptions?

Should these notes be played as a chord or one after another?

Is it a bad idea to replace pull-up resistors with hard pull-ups?

Does Lawful Interception of 4G / the proposed 5G provide a back door for hackers as well?

Why is “Ich wusste, dass aus dir mal was wird” grammitally correct?

What's special about a Bunsen burner?

How does noise-cancellation work in Mac laptops?

Does the 500 feet falling cap apply per fall, or per turn?



Stacking 3D Cubes with Spacing


How to draw a cube as the following?I want to draw cubes stacked on top of each other. Help?Accessing individual table elements with pgfplots?How do I change properties of a cube in TikZ?How do I fix spacing on paths for a nested tikz flowchart?some problems about cubes and tikz pictureHow Can I draw a cube of cubes efficiently?Compound Pathway Problem with holesWord Vector with the help of TikzSpacing between branches of treesDrawing 3d grids (cubes)How to draw cubes in a 3 dimensional plane













8















Is there any way to re-create the top three components of this picture?



enter image description here



I have no idea where to begin. I am not the best with Tikz, but I can see having the spacing between the cubes being a huge pain.










share|improve this question






















  • Related: tex.stackexchange.com/q/455500/1952

    – Ignasi
    May 8 at 7:44















8















Is there any way to re-create the top three components of this picture?



enter image description here



I have no idea where to begin. I am not the best with Tikz, but I can see having the spacing between the cubes being a huge pain.










share|improve this question






















  • Related: tex.stackexchange.com/q/455500/1952

    – Ignasi
    May 8 at 7:44













8












8








8


2






Is there any way to re-create the top three components of this picture?



enter image description here



I have no idea where to begin. I am not the best with Tikz, but I can see having the spacing between the cubes being a huge pain.










share|improve this question














Is there any way to re-create the top three components of this picture?



enter image description here



I have no idea where to begin. I am not the best with Tikz, but I can see having the spacing between the cubes being a huge pain.







tikz-pgf






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 8 at 3:46









Aiden KennyAiden Kenny

5427




5427












  • Related: tex.stackexchange.com/q/455500/1952

    – Ignasi
    May 8 at 7:44

















  • Related: tex.stackexchange.com/q/455500/1952

    – Ignasi
    May 8 at 7:44
















Related: tex.stackexchange.com/q/455500/1952

– Ignasi
May 8 at 7:44





Related: tex.stackexchange.com/q/455500/1952

– Ignasi
May 8 at 7:44










2 Answers
2






active

oldest

votes


















16














This is to give you a start. I essentially recycled and slightly modified the code from this answer. With these definition, drawing the vector is as simple as



path piccube array=num cubes x=3;


MWE:



documentclass[tikz,border=3.14mm]standalone
usepackagetikz-3dplot
usetikzlibrarycalc
tikzsetplane/.style n args=3insert path=%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle,
unit xy plane/.style=plane=#1(1,0,0)(0,1,0),
unit xz plane/.style=plane=#1(1,0,0)(0,0,1),
unit yz plane/.style=plane=#1(0,1,0)(0,0,1),
get projections/.style=insert path=%
let p1=(1,0,0),p2=(0,1,0) in
[/utils/exec=pgfmathtruncatemacroxprojsign(x1)xdefxprojxproj
pgfmathtruncatemacroyprojsign(x2)xdefyprojyproj
pgfmathtruncatemacrozprojsign(cos(tdplotmaintheta))xdefzprojzproj],
pics/unit cube/.style=code=
path[get projections];
draw (0,0,0) -- (1,1,1);
ifnumzproj=-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,0)];
fi
ifnumyproj=1
path[3d cube/every face,3d cube/yz face,unit yz plane=(1,0,0)];
else
path[3d cube/every face,3d cube/yz face,unit yz plane=(0,0,0)];
fi
ifnumxproj=1
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,0,0)];
else
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,1,0)];
fi
ifnumzproj>-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,1)];
fi
,
3d cube/.cd,
xy face/.style=fill=blue!10,
xz face/.style=fill=blue!20,
yz face/.style=fill=blue!30,
num cubes x/.estore in=NumCubesX,
num cubes y/.estore in=NumCubesY,
num cubes z/.estore in=NumCubesZ,
num cubes x=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube scale/.initial=0.9,
every face/.style=draw,very thick,
/tikz/pics/.cd,
cube array/.style=code=%
tikzset3d cube/.cd,#1
%typeoutNumCubesX,NumCubesY,NumCubesZ
path[get projections];
ifnumyproj=1
defLstX1,...,NumCubesX
else
ifnumNumCubesX>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstXNumCubesX,NextToLast,...,1
else
defLstX1
fi
fi
ifnumxproj=-1
defLstY1,...,NumCubesY
else
ifnumNumCubesY>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstYNumCubesY,NextToLast,...,1
else
defLstY1
fi
fi
ifnumzproj=1
defLstZ1,...,NumCubesZ
else
ifnumNumCubesZ>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstZNumCubesZ,NextToLast,...,1
else
defLstZ1
fi
defLstZNumCubesZ,NextToLast,...,1
fi
foreach X in LstX
foreach Y in LstY
foreach Z in LstZ
path (X-NumCubesX/2-1,Y-NumCubesY/2-1,Z-NumCubesY/2-1)
pic[scale=pgfkeysvalueof/tikz/3d cube/cube scale]unit cube;



begindocument
tdplotsetmaincoords60200 % the first argument cannot be larger than 90
begintikzpicture[line join=round,font=sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
beginscope[local bounding box=first row]
beginscope[tdplot_main_coords,local bounding box=vector]
path piccube array=num cubes x=3;
endscope
beginscope[xshift=4cm,tdplot_main_coords,local bounding box=matrix]
path piccube array=num cubes x=3,num cubes z=3;
endscope
beginscope[xshift=8cm,tdplot_main_coords,local bounding box=array]
path piccube array=num cubes x=3,num cubes y=3,num cubes z=3;
endscope
endscope
foreach X in vector,matrix,array
node[above] at (X
%
beginscope[yshift=-5.5cm,local bounding box=data frame,tdplot_main_coords]
foreach Col [count=XX] in blue,purple,green
path (2-XX,0,0)piccube array=num cubes z=3,
xy face/.style=fill=Col!10,
xz face/.style=fill=Col!20,
yz face/.style=fill=Col!30;
endscope
node[above] (df) at (data frame.north)data frame;
%
beginscope[yshift=-3.5cm,xshift=5cm,local bounding box=more]
path foreach XX in -1.5,0,1.5
(XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;
endscope
node at (df-|more)more;

endtikzpicture
enddocument


enter image description here



You can adjust the view at will.



documentclass[tikz,border=3.14mm]standalone
usepackagetikz-3dplot
usetikzlibrarycalc
tikzsetplane/.style n args=3insert path=%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle,
unit xy plane/.style=plane=#1(1,0,0)(0,1,0),
unit xz plane/.style=plane=#1(1,0,0)(0,0,1),
unit yz plane/.style=plane=#1(0,1,0)(0,0,1),
get projections/.style=insert path=%
let p1=(1,0,0),p2=(0,1,0) in
[/utils/exec=pgfmathtruncatemacroxprojsign(x1)xdefxprojxproj
pgfmathtruncatemacroyprojsign(x2)xdefyprojyproj
pgfmathtruncatemacrozprojsign(cos(tdplotmaintheta))xdefzprojzproj],
pics/unit cube/.style=code=
path[get projections];
draw (0,0,0) -- (1,1,1);
ifnumzproj=-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,0)];
fi
ifnumyproj=1
path[3d cube/every face,3d cube/yz face,unit yz plane=(1,0,0)];
else
path[3d cube/every face,3d cube/yz face,unit yz plane=(0,0,0)];
fi
ifnumxproj=1
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,0,0)];
else
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,1,0)];
fi
ifnumzproj>-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,1)];
fi
,
3d cube/.cd,
xy face/.style=fill=blue!10,
xz face/.style=fill=blue!20,
yz face/.style=fill=blue!30,
num cubes x/.estore in=NumCubesX,
num cubes y/.estore in=NumCubesY,
num cubes z/.estore in=NumCubesZ,
num cubes x=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube scale/.initial=0.9,
every face/.style=draw,very thick,
/tikz/pics/.cd,
cube array/.style=code=%
tikzset3d cube/.cd,#1
%typeoutNumCubesX,NumCubesY,NumCubesZ
path[get projections];
ifnumyproj=1
defLstX1,...,NumCubesX
else
ifnumNumCubesX>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstXNumCubesX,NextToLast,...,1
else
defLstX1
fi
fi
ifnumxproj=-1
defLstY1,...,NumCubesY
else
ifnumNumCubesY>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstYNumCubesY,NextToLast,...,1
else
defLstY1
fi
fi
ifnumzproj=1
defLstZ1,...,NumCubesZ
else
ifnumNumCubesZ>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstZNumCubesZ,NextToLast,...,1
else
defLstZ1
fi
defLstZNumCubesZ,NextToLast,...,1
fi
foreach X in LstX
foreach Y in LstY
foreach Z in LstZ
path (X-NumCubesX/2-1,Y-NumCubesY/2-1,Z-NumCubesY/2-1)
pic[scale=pgfkeysvalueof/tikz/3d cube/cube scale]unit cube;



begindocument
foreach Angle in 5,15,...,355
tdplotsetmaincoords60Angle % the first argument cannot be larger than 90
begintikzpicture[line join=round,font=sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
path[use as bounding box] (-3,-3) rectangle (12,4);
beginscope[local bounding box=first row]
beginscope[tdplot_main_coords,local bounding box=vector]
path piccube array=num cubes x=3;
endscope
beginscope[xshift=4cm,tdplot_main_coords,local bounding box=matrix]
path piccube array=num cubes x=3,num cubes z=3;
endscope
beginscope[xshift=8cm,tdplot_main_coords,local bounding box=array]
path piccube array=num cubes x=3,num cubes y=3,num cubes z=3;
endscope
endscope
foreach X in vector,matrix,array
node[below] at (X
endtikzpicture
enddocument


enter image description here






share|improve this answer

























  • big, but it's still complex to work in 3D with Tikz.

    – rpapa
    May 8 at 6:09






  • 1





    @marmot my question might seem stupid but how did you acquire such an extensive knowledge of the tikz package? Was it attained just through reading the pgfmanual?

    – Al_Fh
    May 8 at 6:59






  • 1





    @Al_Fh My knowledge is not very deep and I learn a lot from examples. The pgfmanual is well written.

    – marmot
    May 8 at 7:20












  • @marmot very humble of you! As always, thank you for the great answer!

    – Aiden Kenny
    May 8 at 16:32






  • 1





    @AidenKenny Yes, this what is done at the very end of the first code: ` path foreach XX in -1.5,0,1.5 (XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;. There is an overall scale for the cube array, scale=0.4, and a scale for the single cubes, cube scale=0.36, which has to be a bit smaller than the overall scale in order to have gaps. You may also reduce the line width. Another thing you could do is to store some standard shapes in savebox`es and rescale them as you want.

    – marmot
    May 8 at 16:56


















4














Run it with pdflatex --shell-escape <file>:



documentclassarticle
usepackagepst-ob3d,pst-calculate,multido
usepackageauto-pst-pdf
defCube(#1,#2,#3)PstCube(#1,#2,#3)111
defCubeRow(#1,#2,#3)%
Cube(#1,#2,#3)Cube(#1,pscalculate#2+1.1,#3)Cube(#1,pscalculate#2+2.2,#3)
begindocument

pssetfillstyle=solid,viewpoint=0.6 0.1 0.1,fillcolor=blue!30,linecolor=blue
beginpspicture(0,-0.5)(4,2)
CubeRow(0,0,0)
endpspicture
qquad
beginpspicture(0,-0.5)(4,4)
CubeRow(0,0,0)CubeRow(0,0,1.1)CubeRow(0,0,2.2)
endpspicture
qquad
beginpspicture(0,-0.5)(4,4)
multidorA=-1.3+1.33multidorB=0.0+1.13CubeRow(rA,0,rB)
endpspicture

enddocument


enter image description here






share|improve this answer

























  • On my TeXLive 2019 installation this output is not obtained when compiling this with pdflatex --shell-escape <file>

    – marmot
    May 8 at 14:03











Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "85"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f489712%2fstacking-3d-cubes-with-spacing%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









16














This is to give you a start. I essentially recycled and slightly modified the code from this answer. With these definition, drawing the vector is as simple as



path piccube array=num cubes x=3;


MWE:



documentclass[tikz,border=3.14mm]standalone
usepackagetikz-3dplot
usetikzlibrarycalc
tikzsetplane/.style n args=3insert path=%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle,
unit xy plane/.style=plane=#1(1,0,0)(0,1,0),
unit xz plane/.style=plane=#1(1,0,0)(0,0,1),
unit yz plane/.style=plane=#1(0,1,0)(0,0,1),
get projections/.style=insert path=%
let p1=(1,0,0),p2=(0,1,0) in
[/utils/exec=pgfmathtruncatemacroxprojsign(x1)xdefxprojxproj
pgfmathtruncatemacroyprojsign(x2)xdefyprojyproj
pgfmathtruncatemacrozprojsign(cos(tdplotmaintheta))xdefzprojzproj],
pics/unit cube/.style=code=
path[get projections];
draw (0,0,0) -- (1,1,1);
ifnumzproj=-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,0)];
fi
ifnumyproj=1
path[3d cube/every face,3d cube/yz face,unit yz plane=(1,0,0)];
else
path[3d cube/every face,3d cube/yz face,unit yz plane=(0,0,0)];
fi
ifnumxproj=1
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,0,0)];
else
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,1,0)];
fi
ifnumzproj>-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,1)];
fi
,
3d cube/.cd,
xy face/.style=fill=blue!10,
xz face/.style=fill=blue!20,
yz face/.style=fill=blue!30,
num cubes x/.estore in=NumCubesX,
num cubes y/.estore in=NumCubesY,
num cubes z/.estore in=NumCubesZ,
num cubes x=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube scale/.initial=0.9,
every face/.style=draw,very thick,
/tikz/pics/.cd,
cube array/.style=code=%
tikzset3d cube/.cd,#1
%typeoutNumCubesX,NumCubesY,NumCubesZ
path[get projections];
ifnumyproj=1
defLstX1,...,NumCubesX
else
ifnumNumCubesX>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstXNumCubesX,NextToLast,...,1
else
defLstX1
fi
fi
ifnumxproj=-1
defLstY1,...,NumCubesY
else
ifnumNumCubesY>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstYNumCubesY,NextToLast,...,1
else
defLstY1
fi
fi
ifnumzproj=1
defLstZ1,...,NumCubesZ
else
ifnumNumCubesZ>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstZNumCubesZ,NextToLast,...,1
else
defLstZ1
fi
defLstZNumCubesZ,NextToLast,...,1
fi
foreach X in LstX
foreach Y in LstY
foreach Z in LstZ
path (X-NumCubesX/2-1,Y-NumCubesY/2-1,Z-NumCubesY/2-1)
pic[scale=pgfkeysvalueof/tikz/3d cube/cube scale]unit cube;



begindocument
tdplotsetmaincoords60200 % the first argument cannot be larger than 90
begintikzpicture[line join=round,font=sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
beginscope[local bounding box=first row]
beginscope[tdplot_main_coords,local bounding box=vector]
path piccube array=num cubes x=3;
endscope
beginscope[xshift=4cm,tdplot_main_coords,local bounding box=matrix]
path piccube array=num cubes x=3,num cubes z=3;
endscope
beginscope[xshift=8cm,tdplot_main_coords,local bounding box=array]
path piccube array=num cubes x=3,num cubes y=3,num cubes z=3;
endscope
endscope
foreach X in vector,matrix,array
node[above] at (X
%
beginscope[yshift=-5.5cm,local bounding box=data frame,tdplot_main_coords]
foreach Col [count=XX] in blue,purple,green
path (2-XX,0,0)piccube array=num cubes z=3,
xy face/.style=fill=Col!10,
xz face/.style=fill=Col!20,
yz face/.style=fill=Col!30;
endscope
node[above] (df) at (data frame.north)data frame;
%
beginscope[yshift=-3.5cm,xshift=5cm,local bounding box=more]
path foreach XX in -1.5,0,1.5
(XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;
endscope
node at (df-|more)more;

endtikzpicture
enddocument


enter image description here



You can adjust the view at will.



documentclass[tikz,border=3.14mm]standalone
usepackagetikz-3dplot
usetikzlibrarycalc
tikzsetplane/.style n args=3insert path=%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle,
unit xy plane/.style=plane=#1(1,0,0)(0,1,0),
unit xz plane/.style=plane=#1(1,0,0)(0,0,1),
unit yz plane/.style=plane=#1(0,1,0)(0,0,1),
get projections/.style=insert path=%
let p1=(1,0,0),p2=(0,1,0) in
[/utils/exec=pgfmathtruncatemacroxprojsign(x1)xdefxprojxproj
pgfmathtruncatemacroyprojsign(x2)xdefyprojyproj
pgfmathtruncatemacrozprojsign(cos(tdplotmaintheta))xdefzprojzproj],
pics/unit cube/.style=code=
path[get projections];
draw (0,0,0) -- (1,1,1);
ifnumzproj=-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,0)];
fi
ifnumyproj=1
path[3d cube/every face,3d cube/yz face,unit yz plane=(1,0,0)];
else
path[3d cube/every face,3d cube/yz face,unit yz plane=(0,0,0)];
fi
ifnumxproj=1
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,0,0)];
else
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,1,0)];
fi
ifnumzproj>-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,1)];
fi
,
3d cube/.cd,
xy face/.style=fill=blue!10,
xz face/.style=fill=blue!20,
yz face/.style=fill=blue!30,
num cubes x/.estore in=NumCubesX,
num cubes y/.estore in=NumCubesY,
num cubes z/.estore in=NumCubesZ,
num cubes x=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube scale/.initial=0.9,
every face/.style=draw,very thick,
/tikz/pics/.cd,
cube array/.style=code=%
tikzset3d cube/.cd,#1
%typeoutNumCubesX,NumCubesY,NumCubesZ
path[get projections];
ifnumyproj=1
defLstX1,...,NumCubesX
else
ifnumNumCubesX>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstXNumCubesX,NextToLast,...,1
else
defLstX1
fi
fi
ifnumxproj=-1
defLstY1,...,NumCubesY
else
ifnumNumCubesY>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstYNumCubesY,NextToLast,...,1
else
defLstY1
fi
fi
ifnumzproj=1
defLstZ1,...,NumCubesZ
else
ifnumNumCubesZ>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstZNumCubesZ,NextToLast,...,1
else
defLstZ1
fi
defLstZNumCubesZ,NextToLast,...,1
fi
foreach X in LstX
foreach Y in LstY
foreach Z in LstZ
path (X-NumCubesX/2-1,Y-NumCubesY/2-1,Z-NumCubesY/2-1)
pic[scale=pgfkeysvalueof/tikz/3d cube/cube scale]unit cube;



begindocument
foreach Angle in 5,15,...,355
tdplotsetmaincoords60Angle % the first argument cannot be larger than 90
begintikzpicture[line join=round,font=sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
path[use as bounding box] (-3,-3) rectangle (12,4);
beginscope[local bounding box=first row]
beginscope[tdplot_main_coords,local bounding box=vector]
path piccube array=num cubes x=3;
endscope
beginscope[xshift=4cm,tdplot_main_coords,local bounding box=matrix]
path piccube array=num cubes x=3,num cubes z=3;
endscope
beginscope[xshift=8cm,tdplot_main_coords,local bounding box=array]
path piccube array=num cubes x=3,num cubes y=3,num cubes z=3;
endscope
endscope
foreach X in vector,matrix,array
node[below] at (X
endtikzpicture
enddocument


enter image description here






share|improve this answer

























  • big, but it's still complex to work in 3D with Tikz.

    – rpapa
    May 8 at 6:09






  • 1





    @marmot my question might seem stupid but how did you acquire such an extensive knowledge of the tikz package? Was it attained just through reading the pgfmanual?

    – Al_Fh
    May 8 at 6:59






  • 1





    @Al_Fh My knowledge is not very deep and I learn a lot from examples. The pgfmanual is well written.

    – marmot
    May 8 at 7:20












  • @marmot very humble of you! As always, thank you for the great answer!

    – Aiden Kenny
    May 8 at 16:32






  • 1





    @AidenKenny Yes, this what is done at the very end of the first code: ` path foreach XX in -1.5,0,1.5 (XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;. There is an overall scale for the cube array, scale=0.4, and a scale for the single cubes, cube scale=0.36, which has to be a bit smaller than the overall scale in order to have gaps. You may also reduce the line width. Another thing you could do is to store some standard shapes in savebox`es and rescale them as you want.

    – marmot
    May 8 at 16:56















16














This is to give you a start. I essentially recycled and slightly modified the code from this answer. With these definition, drawing the vector is as simple as



path piccube array=num cubes x=3;


MWE:



documentclass[tikz,border=3.14mm]standalone
usepackagetikz-3dplot
usetikzlibrarycalc
tikzsetplane/.style n args=3insert path=%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle,
unit xy plane/.style=plane=#1(1,0,0)(0,1,0),
unit xz plane/.style=plane=#1(1,0,0)(0,0,1),
unit yz plane/.style=plane=#1(0,1,0)(0,0,1),
get projections/.style=insert path=%
let p1=(1,0,0),p2=(0,1,0) in
[/utils/exec=pgfmathtruncatemacroxprojsign(x1)xdefxprojxproj
pgfmathtruncatemacroyprojsign(x2)xdefyprojyproj
pgfmathtruncatemacrozprojsign(cos(tdplotmaintheta))xdefzprojzproj],
pics/unit cube/.style=code=
path[get projections];
draw (0,0,0) -- (1,1,1);
ifnumzproj=-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,0)];
fi
ifnumyproj=1
path[3d cube/every face,3d cube/yz face,unit yz plane=(1,0,0)];
else
path[3d cube/every face,3d cube/yz face,unit yz plane=(0,0,0)];
fi
ifnumxproj=1
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,0,0)];
else
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,1,0)];
fi
ifnumzproj>-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,1)];
fi
,
3d cube/.cd,
xy face/.style=fill=blue!10,
xz face/.style=fill=blue!20,
yz face/.style=fill=blue!30,
num cubes x/.estore in=NumCubesX,
num cubes y/.estore in=NumCubesY,
num cubes z/.estore in=NumCubesZ,
num cubes x=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube scale/.initial=0.9,
every face/.style=draw,very thick,
/tikz/pics/.cd,
cube array/.style=code=%
tikzset3d cube/.cd,#1
%typeoutNumCubesX,NumCubesY,NumCubesZ
path[get projections];
ifnumyproj=1
defLstX1,...,NumCubesX
else
ifnumNumCubesX>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstXNumCubesX,NextToLast,...,1
else
defLstX1
fi
fi
ifnumxproj=-1
defLstY1,...,NumCubesY
else
ifnumNumCubesY>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstYNumCubesY,NextToLast,...,1
else
defLstY1
fi
fi
ifnumzproj=1
defLstZ1,...,NumCubesZ
else
ifnumNumCubesZ>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstZNumCubesZ,NextToLast,...,1
else
defLstZ1
fi
defLstZNumCubesZ,NextToLast,...,1
fi
foreach X in LstX
foreach Y in LstY
foreach Z in LstZ
path (X-NumCubesX/2-1,Y-NumCubesY/2-1,Z-NumCubesY/2-1)
pic[scale=pgfkeysvalueof/tikz/3d cube/cube scale]unit cube;



begindocument
tdplotsetmaincoords60200 % the first argument cannot be larger than 90
begintikzpicture[line join=round,font=sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
beginscope[local bounding box=first row]
beginscope[tdplot_main_coords,local bounding box=vector]
path piccube array=num cubes x=3;
endscope
beginscope[xshift=4cm,tdplot_main_coords,local bounding box=matrix]
path piccube array=num cubes x=3,num cubes z=3;
endscope
beginscope[xshift=8cm,tdplot_main_coords,local bounding box=array]
path piccube array=num cubes x=3,num cubes y=3,num cubes z=3;
endscope
endscope
foreach X in vector,matrix,array
node[above] at (X
%
beginscope[yshift=-5.5cm,local bounding box=data frame,tdplot_main_coords]
foreach Col [count=XX] in blue,purple,green
path (2-XX,0,0)piccube array=num cubes z=3,
xy face/.style=fill=Col!10,
xz face/.style=fill=Col!20,
yz face/.style=fill=Col!30;
endscope
node[above] (df) at (data frame.north)data frame;
%
beginscope[yshift=-3.5cm,xshift=5cm,local bounding box=more]
path foreach XX in -1.5,0,1.5
(XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;
endscope
node at (df-|more)more;

endtikzpicture
enddocument


enter image description here



You can adjust the view at will.



documentclass[tikz,border=3.14mm]standalone
usepackagetikz-3dplot
usetikzlibrarycalc
tikzsetplane/.style n args=3insert path=%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle,
unit xy plane/.style=plane=#1(1,0,0)(0,1,0),
unit xz plane/.style=plane=#1(1,0,0)(0,0,1),
unit yz plane/.style=plane=#1(0,1,0)(0,0,1),
get projections/.style=insert path=%
let p1=(1,0,0),p2=(0,1,0) in
[/utils/exec=pgfmathtruncatemacroxprojsign(x1)xdefxprojxproj
pgfmathtruncatemacroyprojsign(x2)xdefyprojyproj
pgfmathtruncatemacrozprojsign(cos(tdplotmaintheta))xdefzprojzproj],
pics/unit cube/.style=code=
path[get projections];
draw (0,0,0) -- (1,1,1);
ifnumzproj=-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,0)];
fi
ifnumyproj=1
path[3d cube/every face,3d cube/yz face,unit yz plane=(1,0,0)];
else
path[3d cube/every face,3d cube/yz face,unit yz plane=(0,0,0)];
fi
ifnumxproj=1
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,0,0)];
else
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,1,0)];
fi
ifnumzproj>-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,1)];
fi
,
3d cube/.cd,
xy face/.style=fill=blue!10,
xz face/.style=fill=blue!20,
yz face/.style=fill=blue!30,
num cubes x/.estore in=NumCubesX,
num cubes y/.estore in=NumCubesY,
num cubes z/.estore in=NumCubesZ,
num cubes x=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube scale/.initial=0.9,
every face/.style=draw,very thick,
/tikz/pics/.cd,
cube array/.style=code=%
tikzset3d cube/.cd,#1
%typeoutNumCubesX,NumCubesY,NumCubesZ
path[get projections];
ifnumyproj=1
defLstX1,...,NumCubesX
else
ifnumNumCubesX>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstXNumCubesX,NextToLast,...,1
else
defLstX1
fi
fi
ifnumxproj=-1
defLstY1,...,NumCubesY
else
ifnumNumCubesY>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstYNumCubesY,NextToLast,...,1
else
defLstY1
fi
fi
ifnumzproj=1
defLstZ1,...,NumCubesZ
else
ifnumNumCubesZ>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstZNumCubesZ,NextToLast,...,1
else
defLstZ1
fi
defLstZNumCubesZ,NextToLast,...,1
fi
foreach X in LstX
foreach Y in LstY
foreach Z in LstZ
path (X-NumCubesX/2-1,Y-NumCubesY/2-1,Z-NumCubesY/2-1)
pic[scale=pgfkeysvalueof/tikz/3d cube/cube scale]unit cube;



begindocument
foreach Angle in 5,15,...,355
tdplotsetmaincoords60Angle % the first argument cannot be larger than 90
begintikzpicture[line join=round,font=sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
path[use as bounding box] (-3,-3) rectangle (12,4);
beginscope[local bounding box=first row]
beginscope[tdplot_main_coords,local bounding box=vector]
path piccube array=num cubes x=3;
endscope
beginscope[xshift=4cm,tdplot_main_coords,local bounding box=matrix]
path piccube array=num cubes x=3,num cubes z=3;
endscope
beginscope[xshift=8cm,tdplot_main_coords,local bounding box=array]
path piccube array=num cubes x=3,num cubes y=3,num cubes z=3;
endscope
endscope
foreach X in vector,matrix,array
node[below] at (X
endtikzpicture
enddocument


enter image description here






share|improve this answer

























  • big, but it's still complex to work in 3D with Tikz.

    – rpapa
    May 8 at 6:09






  • 1





    @marmot my question might seem stupid but how did you acquire such an extensive knowledge of the tikz package? Was it attained just through reading the pgfmanual?

    – Al_Fh
    May 8 at 6:59






  • 1





    @Al_Fh My knowledge is not very deep and I learn a lot from examples. The pgfmanual is well written.

    – marmot
    May 8 at 7:20












  • @marmot very humble of you! As always, thank you for the great answer!

    – Aiden Kenny
    May 8 at 16:32






  • 1





    @AidenKenny Yes, this what is done at the very end of the first code: ` path foreach XX in -1.5,0,1.5 (XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;. There is an overall scale for the cube array, scale=0.4, and a scale for the single cubes, cube scale=0.36, which has to be a bit smaller than the overall scale in order to have gaps. You may also reduce the line width. Another thing you could do is to store some standard shapes in savebox`es and rescale them as you want.

    – marmot
    May 8 at 16:56













16












16








16







This is to give you a start. I essentially recycled and slightly modified the code from this answer. With these definition, drawing the vector is as simple as



path piccube array=num cubes x=3;


MWE:



documentclass[tikz,border=3.14mm]standalone
usepackagetikz-3dplot
usetikzlibrarycalc
tikzsetplane/.style n args=3insert path=%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle,
unit xy plane/.style=plane=#1(1,0,0)(0,1,0),
unit xz plane/.style=plane=#1(1,0,0)(0,0,1),
unit yz plane/.style=plane=#1(0,1,0)(0,0,1),
get projections/.style=insert path=%
let p1=(1,0,0),p2=(0,1,0) in
[/utils/exec=pgfmathtruncatemacroxprojsign(x1)xdefxprojxproj
pgfmathtruncatemacroyprojsign(x2)xdefyprojyproj
pgfmathtruncatemacrozprojsign(cos(tdplotmaintheta))xdefzprojzproj],
pics/unit cube/.style=code=
path[get projections];
draw (0,0,0) -- (1,1,1);
ifnumzproj=-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,0)];
fi
ifnumyproj=1
path[3d cube/every face,3d cube/yz face,unit yz plane=(1,0,0)];
else
path[3d cube/every face,3d cube/yz face,unit yz plane=(0,0,0)];
fi
ifnumxproj=1
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,0,0)];
else
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,1,0)];
fi
ifnumzproj>-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,1)];
fi
,
3d cube/.cd,
xy face/.style=fill=blue!10,
xz face/.style=fill=blue!20,
yz face/.style=fill=blue!30,
num cubes x/.estore in=NumCubesX,
num cubes y/.estore in=NumCubesY,
num cubes z/.estore in=NumCubesZ,
num cubes x=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube scale/.initial=0.9,
every face/.style=draw,very thick,
/tikz/pics/.cd,
cube array/.style=code=%
tikzset3d cube/.cd,#1
%typeoutNumCubesX,NumCubesY,NumCubesZ
path[get projections];
ifnumyproj=1
defLstX1,...,NumCubesX
else
ifnumNumCubesX>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstXNumCubesX,NextToLast,...,1
else
defLstX1
fi
fi
ifnumxproj=-1
defLstY1,...,NumCubesY
else
ifnumNumCubesY>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstYNumCubesY,NextToLast,...,1
else
defLstY1
fi
fi
ifnumzproj=1
defLstZ1,...,NumCubesZ
else
ifnumNumCubesZ>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstZNumCubesZ,NextToLast,...,1
else
defLstZ1
fi
defLstZNumCubesZ,NextToLast,...,1
fi
foreach X in LstX
foreach Y in LstY
foreach Z in LstZ
path (X-NumCubesX/2-1,Y-NumCubesY/2-1,Z-NumCubesY/2-1)
pic[scale=pgfkeysvalueof/tikz/3d cube/cube scale]unit cube;



begindocument
tdplotsetmaincoords60200 % the first argument cannot be larger than 90
begintikzpicture[line join=round,font=sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
beginscope[local bounding box=first row]
beginscope[tdplot_main_coords,local bounding box=vector]
path piccube array=num cubes x=3;
endscope
beginscope[xshift=4cm,tdplot_main_coords,local bounding box=matrix]
path piccube array=num cubes x=3,num cubes z=3;
endscope
beginscope[xshift=8cm,tdplot_main_coords,local bounding box=array]
path piccube array=num cubes x=3,num cubes y=3,num cubes z=3;
endscope
endscope
foreach X in vector,matrix,array
node[above] at (X
%
beginscope[yshift=-5.5cm,local bounding box=data frame,tdplot_main_coords]
foreach Col [count=XX] in blue,purple,green
path (2-XX,0,0)piccube array=num cubes z=3,
xy face/.style=fill=Col!10,
xz face/.style=fill=Col!20,
yz face/.style=fill=Col!30;
endscope
node[above] (df) at (data frame.north)data frame;
%
beginscope[yshift=-3.5cm,xshift=5cm,local bounding box=more]
path foreach XX in -1.5,0,1.5
(XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;
endscope
node at (df-|more)more;

endtikzpicture
enddocument


enter image description here



You can adjust the view at will.



documentclass[tikz,border=3.14mm]standalone
usepackagetikz-3dplot
usetikzlibrarycalc
tikzsetplane/.style n args=3insert path=%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle,
unit xy plane/.style=plane=#1(1,0,0)(0,1,0),
unit xz plane/.style=plane=#1(1,0,0)(0,0,1),
unit yz plane/.style=plane=#1(0,1,0)(0,0,1),
get projections/.style=insert path=%
let p1=(1,0,0),p2=(0,1,0) in
[/utils/exec=pgfmathtruncatemacroxprojsign(x1)xdefxprojxproj
pgfmathtruncatemacroyprojsign(x2)xdefyprojyproj
pgfmathtruncatemacrozprojsign(cos(tdplotmaintheta))xdefzprojzproj],
pics/unit cube/.style=code=
path[get projections];
draw (0,0,0) -- (1,1,1);
ifnumzproj=-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,0)];
fi
ifnumyproj=1
path[3d cube/every face,3d cube/yz face,unit yz plane=(1,0,0)];
else
path[3d cube/every face,3d cube/yz face,unit yz plane=(0,0,0)];
fi
ifnumxproj=1
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,0,0)];
else
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,1,0)];
fi
ifnumzproj>-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,1)];
fi
,
3d cube/.cd,
xy face/.style=fill=blue!10,
xz face/.style=fill=blue!20,
yz face/.style=fill=blue!30,
num cubes x/.estore in=NumCubesX,
num cubes y/.estore in=NumCubesY,
num cubes z/.estore in=NumCubesZ,
num cubes x=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube scale/.initial=0.9,
every face/.style=draw,very thick,
/tikz/pics/.cd,
cube array/.style=code=%
tikzset3d cube/.cd,#1
%typeoutNumCubesX,NumCubesY,NumCubesZ
path[get projections];
ifnumyproj=1
defLstX1,...,NumCubesX
else
ifnumNumCubesX>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstXNumCubesX,NextToLast,...,1
else
defLstX1
fi
fi
ifnumxproj=-1
defLstY1,...,NumCubesY
else
ifnumNumCubesY>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstYNumCubesY,NextToLast,...,1
else
defLstY1
fi
fi
ifnumzproj=1
defLstZ1,...,NumCubesZ
else
ifnumNumCubesZ>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstZNumCubesZ,NextToLast,...,1
else
defLstZ1
fi
defLstZNumCubesZ,NextToLast,...,1
fi
foreach X in LstX
foreach Y in LstY
foreach Z in LstZ
path (X-NumCubesX/2-1,Y-NumCubesY/2-1,Z-NumCubesY/2-1)
pic[scale=pgfkeysvalueof/tikz/3d cube/cube scale]unit cube;



begindocument
foreach Angle in 5,15,...,355
tdplotsetmaincoords60Angle % the first argument cannot be larger than 90
begintikzpicture[line join=round,font=sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
path[use as bounding box] (-3,-3) rectangle (12,4);
beginscope[local bounding box=first row]
beginscope[tdplot_main_coords,local bounding box=vector]
path piccube array=num cubes x=3;
endscope
beginscope[xshift=4cm,tdplot_main_coords,local bounding box=matrix]
path piccube array=num cubes x=3,num cubes z=3;
endscope
beginscope[xshift=8cm,tdplot_main_coords,local bounding box=array]
path piccube array=num cubes x=3,num cubes y=3,num cubes z=3;
endscope
endscope
foreach X in vector,matrix,array
node[below] at (X
endtikzpicture
enddocument


enter image description here






share|improve this answer















This is to give you a start. I essentially recycled and slightly modified the code from this answer. With these definition, drawing the vector is as simple as



path piccube array=num cubes x=3;


MWE:



documentclass[tikz,border=3.14mm]standalone
usepackagetikz-3dplot
usetikzlibrarycalc
tikzsetplane/.style n args=3insert path=%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle,
unit xy plane/.style=plane=#1(1,0,0)(0,1,0),
unit xz plane/.style=plane=#1(1,0,0)(0,0,1),
unit yz plane/.style=plane=#1(0,1,0)(0,0,1),
get projections/.style=insert path=%
let p1=(1,0,0),p2=(0,1,0) in
[/utils/exec=pgfmathtruncatemacroxprojsign(x1)xdefxprojxproj
pgfmathtruncatemacroyprojsign(x2)xdefyprojyproj
pgfmathtruncatemacrozprojsign(cos(tdplotmaintheta))xdefzprojzproj],
pics/unit cube/.style=code=
path[get projections];
draw (0,0,0) -- (1,1,1);
ifnumzproj=-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,0)];
fi
ifnumyproj=1
path[3d cube/every face,3d cube/yz face,unit yz plane=(1,0,0)];
else
path[3d cube/every face,3d cube/yz face,unit yz plane=(0,0,0)];
fi
ifnumxproj=1
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,0,0)];
else
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,1,0)];
fi
ifnumzproj>-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,1)];
fi
,
3d cube/.cd,
xy face/.style=fill=blue!10,
xz face/.style=fill=blue!20,
yz face/.style=fill=blue!30,
num cubes x/.estore in=NumCubesX,
num cubes y/.estore in=NumCubesY,
num cubes z/.estore in=NumCubesZ,
num cubes x=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube scale/.initial=0.9,
every face/.style=draw,very thick,
/tikz/pics/.cd,
cube array/.style=code=%
tikzset3d cube/.cd,#1
%typeoutNumCubesX,NumCubesY,NumCubesZ
path[get projections];
ifnumyproj=1
defLstX1,...,NumCubesX
else
ifnumNumCubesX>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstXNumCubesX,NextToLast,...,1
else
defLstX1
fi
fi
ifnumxproj=-1
defLstY1,...,NumCubesY
else
ifnumNumCubesY>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstYNumCubesY,NextToLast,...,1
else
defLstY1
fi
fi
ifnumzproj=1
defLstZ1,...,NumCubesZ
else
ifnumNumCubesZ>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstZNumCubesZ,NextToLast,...,1
else
defLstZ1
fi
defLstZNumCubesZ,NextToLast,...,1
fi
foreach X in LstX
foreach Y in LstY
foreach Z in LstZ
path (X-NumCubesX/2-1,Y-NumCubesY/2-1,Z-NumCubesY/2-1)
pic[scale=pgfkeysvalueof/tikz/3d cube/cube scale]unit cube;



begindocument
tdplotsetmaincoords60200 % the first argument cannot be larger than 90
begintikzpicture[line join=round,font=sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
beginscope[local bounding box=first row]
beginscope[tdplot_main_coords,local bounding box=vector]
path piccube array=num cubes x=3;
endscope
beginscope[xshift=4cm,tdplot_main_coords,local bounding box=matrix]
path piccube array=num cubes x=3,num cubes z=3;
endscope
beginscope[xshift=8cm,tdplot_main_coords,local bounding box=array]
path piccube array=num cubes x=3,num cubes y=3,num cubes z=3;
endscope
endscope
foreach X in vector,matrix,array
node[above] at (X
%
beginscope[yshift=-5.5cm,local bounding box=data frame,tdplot_main_coords]
foreach Col [count=XX] in blue,purple,green
path (2-XX,0,0)piccube array=num cubes z=3,
xy face/.style=fill=Col!10,
xz face/.style=fill=Col!20,
yz face/.style=fill=Col!30;
endscope
node[above] (df) at (data frame.north)data frame;
%
beginscope[yshift=-3.5cm,xshift=5cm,local bounding box=more]
path foreach XX in -1.5,0,1.5
(XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;
endscope
node at (df-|more)more;

endtikzpicture
enddocument


enter image description here



You can adjust the view at will.



documentclass[tikz,border=3.14mm]standalone
usepackagetikz-3dplot
usetikzlibrarycalc
tikzsetplane/.style n args=3insert path=%
#1 -- ++ #2 -- ++ #3 -- ++ ($-1*#2$) -- cycle,
unit xy plane/.style=plane=#1(1,0,0)(0,1,0),
unit xz plane/.style=plane=#1(1,0,0)(0,0,1),
unit yz plane/.style=plane=#1(0,1,0)(0,0,1),
get projections/.style=insert path=%
let p1=(1,0,0),p2=(0,1,0) in
[/utils/exec=pgfmathtruncatemacroxprojsign(x1)xdefxprojxproj
pgfmathtruncatemacroyprojsign(x2)xdefyprojyproj
pgfmathtruncatemacrozprojsign(cos(tdplotmaintheta))xdefzprojzproj],
pics/unit cube/.style=code=
path[get projections];
draw (0,0,0) -- (1,1,1);
ifnumzproj=-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,0)];
fi
ifnumyproj=1
path[3d cube/every face,3d cube/yz face,unit yz plane=(1,0,0)];
else
path[3d cube/every face,3d cube/yz face,unit yz plane=(0,0,0)];
fi
ifnumxproj=1
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,0,0)];
else
path[3d cube/every face,3d cube/xz face,unit xz plane=(0,1,0)];
fi
ifnumzproj>-1
path[3d cube/every face,3d cube/xy face,unit xy plane=(0,0,1)];
fi
,
3d cube/.cd,
xy face/.style=fill=blue!10,
xz face/.style=fill=blue!20,
yz face/.style=fill=blue!30,
num cubes x/.estore in=NumCubesX,
num cubes y/.estore in=NumCubesY,
num cubes z/.estore in=NumCubesZ,
num cubes x=1,num cubes y/.initial=1,num cubes z/.initial=1,
cube scale/.initial=0.9,
every face/.style=draw,very thick,
/tikz/pics/.cd,
cube array/.style=code=%
tikzset3d cube/.cd,#1
%typeoutNumCubesX,NumCubesY,NumCubesZ
path[get projections];
ifnumyproj=1
defLstX1,...,NumCubesX
else
ifnumNumCubesX>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstXNumCubesX,NextToLast,...,1
else
defLstX1
fi
fi
ifnumxproj=-1
defLstY1,...,NumCubesY
else
ifnumNumCubesY>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstYNumCubesY,NextToLast,...,1
else
defLstY1
fi
fi
ifnumzproj=1
defLstZ1,...,NumCubesZ
else
ifnumNumCubesZ>1
pgfmathtruncatemacroNextToLastNumCubesX-1
defLstZNumCubesZ,NextToLast,...,1
else
defLstZ1
fi
defLstZNumCubesZ,NextToLast,...,1
fi
foreach X in LstX
foreach Y in LstY
foreach Z in LstZ
path (X-NumCubesX/2-1,Y-NumCubesY/2-1,Z-NumCubesY/2-1)
pic[scale=pgfkeysvalueof/tikz/3d cube/cube scale]unit cube;



begindocument
foreach Angle in 5,15,...,355
tdplotsetmaincoords60Angle % the first argument cannot be larger than 90
begintikzpicture[line join=round,font=sffamily,3d cube/.cd,
num cubes x=1,num cubes y=1,num cubes z=1]
path[use as bounding box] (-3,-3) rectangle (12,4);
beginscope[local bounding box=first row]
beginscope[tdplot_main_coords,local bounding box=vector]
path piccube array=num cubes x=3;
endscope
beginscope[xshift=4cm,tdplot_main_coords,local bounding box=matrix]
path piccube array=num cubes x=3,num cubes z=3;
endscope
beginscope[xshift=8cm,tdplot_main_coords,local bounding box=array]
path piccube array=num cubes x=3,num cubes y=3,num cubes z=3;
endscope
endscope
foreach X in vector,matrix,array
node[below] at (X
endtikzpicture
enddocument


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited May 8 at 6:49

























answered May 8 at 5:08









marmotmarmot

126k6162308




126k6162308












  • big, but it's still complex to work in 3D with Tikz.

    – rpapa
    May 8 at 6:09






  • 1





    @marmot my question might seem stupid but how did you acquire such an extensive knowledge of the tikz package? Was it attained just through reading the pgfmanual?

    – Al_Fh
    May 8 at 6:59






  • 1





    @Al_Fh My knowledge is not very deep and I learn a lot from examples. The pgfmanual is well written.

    – marmot
    May 8 at 7:20












  • @marmot very humble of you! As always, thank you for the great answer!

    – Aiden Kenny
    May 8 at 16:32






  • 1





    @AidenKenny Yes, this what is done at the very end of the first code: ` path foreach XX in -1.5,0,1.5 (XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;. There is an overall scale for the cube array, scale=0.4, and a scale for the single cubes, cube scale=0.36, which has to be a bit smaller than the overall scale in order to have gaps. You may also reduce the line width. Another thing you could do is to store some standard shapes in savebox`es and rescale them as you want.

    – marmot
    May 8 at 16:56

















  • big, but it's still complex to work in 3D with Tikz.

    – rpapa
    May 8 at 6:09






  • 1





    @marmot my question might seem stupid but how did you acquire such an extensive knowledge of the tikz package? Was it attained just through reading the pgfmanual?

    – Al_Fh
    May 8 at 6:59






  • 1





    @Al_Fh My knowledge is not very deep and I learn a lot from examples. The pgfmanual is well written.

    – marmot
    May 8 at 7:20












  • @marmot very humble of you! As always, thank you for the great answer!

    – Aiden Kenny
    May 8 at 16:32






  • 1





    @AidenKenny Yes, this what is done at the very end of the first code: ` path foreach XX in -1.5,0,1.5 (XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;. There is an overall scale for the cube array, scale=0.4, and a scale for the single cubes, cube scale=0.36, which has to be a bit smaller than the overall scale in order to have gaps. You may also reduce the line width. Another thing you could do is to store some standard shapes in savebox`es and rescale them as you want.

    – marmot
    May 8 at 16:56
















big, but it's still complex to work in 3D with Tikz.

– rpapa
May 8 at 6:09





big, but it's still complex to work in 3D with Tikz.

– rpapa
May 8 at 6:09




1




1





@marmot my question might seem stupid but how did you acquire such an extensive knowledge of the tikz package? Was it attained just through reading the pgfmanual?

– Al_Fh
May 8 at 6:59





@marmot my question might seem stupid but how did you acquire such an extensive knowledge of the tikz package? Was it attained just through reading the pgfmanual?

– Al_Fh
May 8 at 6:59




1




1





@Al_Fh My knowledge is not very deep and I learn a lot from examples. The pgfmanual is well written.

– marmot
May 8 at 7:20






@Al_Fh My knowledge is not very deep and I learn a lot from examples. The pgfmanual is well written.

– marmot
May 8 at 7:20














@marmot very humble of you! As always, thank you for the great answer!

– Aiden Kenny
May 8 at 16:32





@marmot very humble of you! As always, thank you for the great answer!

– Aiden Kenny
May 8 at 16:32




1




1





@AidenKenny Yes, this what is done at the very end of the first code: ` path foreach XX in -1.5,0,1.5 (XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;. There is an overall scale for the cube array, scale=0.4, and a scale for the single cubes, cube scale=0.36, which has to be a bit smaller than the overall scale in order to have gaps. You may also reduce the line width. Another thing you could do is to store some standard shapes in savebox`es and rescale them as you want.

– marmot
May 8 at 16:56





@AidenKenny Yes, this what is done at the very end of the first code: ` path foreach XX in -1.5,0,1.5 (XX,0,0) pic[tdplot_main_coords,scale=0.4]cube array=num cubes x=3,cube scale=0.36;. There is an overall scale for the cube array, scale=0.4, and a scale for the single cubes, cube scale=0.36, which has to be a bit smaller than the overall scale in order to have gaps. You may also reduce the line width. Another thing you could do is to store some standard shapes in savebox`es and rescale them as you want.

– marmot
May 8 at 16:56











4














Run it with pdflatex --shell-escape <file>:



documentclassarticle
usepackagepst-ob3d,pst-calculate,multido
usepackageauto-pst-pdf
defCube(#1,#2,#3)PstCube(#1,#2,#3)111
defCubeRow(#1,#2,#3)%
Cube(#1,#2,#3)Cube(#1,pscalculate#2+1.1,#3)Cube(#1,pscalculate#2+2.2,#3)
begindocument

pssetfillstyle=solid,viewpoint=0.6 0.1 0.1,fillcolor=blue!30,linecolor=blue
beginpspicture(0,-0.5)(4,2)
CubeRow(0,0,0)
endpspicture
qquad
beginpspicture(0,-0.5)(4,4)
CubeRow(0,0,0)CubeRow(0,0,1.1)CubeRow(0,0,2.2)
endpspicture
qquad
beginpspicture(0,-0.5)(4,4)
multidorA=-1.3+1.33multidorB=0.0+1.13CubeRow(rA,0,rB)
endpspicture

enddocument


enter image description here






share|improve this answer

























  • On my TeXLive 2019 installation this output is not obtained when compiling this with pdflatex --shell-escape <file>

    – marmot
    May 8 at 14:03















4














Run it with pdflatex --shell-escape <file>:



documentclassarticle
usepackagepst-ob3d,pst-calculate,multido
usepackageauto-pst-pdf
defCube(#1,#2,#3)PstCube(#1,#2,#3)111
defCubeRow(#1,#2,#3)%
Cube(#1,#2,#3)Cube(#1,pscalculate#2+1.1,#3)Cube(#1,pscalculate#2+2.2,#3)
begindocument

pssetfillstyle=solid,viewpoint=0.6 0.1 0.1,fillcolor=blue!30,linecolor=blue
beginpspicture(0,-0.5)(4,2)
CubeRow(0,0,0)
endpspicture
qquad
beginpspicture(0,-0.5)(4,4)
CubeRow(0,0,0)CubeRow(0,0,1.1)CubeRow(0,0,2.2)
endpspicture
qquad
beginpspicture(0,-0.5)(4,4)
multidorA=-1.3+1.33multidorB=0.0+1.13CubeRow(rA,0,rB)
endpspicture

enddocument


enter image description here






share|improve this answer

























  • On my TeXLive 2019 installation this output is not obtained when compiling this with pdflatex --shell-escape <file>

    – marmot
    May 8 at 14:03













4












4








4







Run it with pdflatex --shell-escape <file>:



documentclassarticle
usepackagepst-ob3d,pst-calculate,multido
usepackageauto-pst-pdf
defCube(#1,#2,#3)PstCube(#1,#2,#3)111
defCubeRow(#1,#2,#3)%
Cube(#1,#2,#3)Cube(#1,pscalculate#2+1.1,#3)Cube(#1,pscalculate#2+2.2,#3)
begindocument

pssetfillstyle=solid,viewpoint=0.6 0.1 0.1,fillcolor=blue!30,linecolor=blue
beginpspicture(0,-0.5)(4,2)
CubeRow(0,0,0)
endpspicture
qquad
beginpspicture(0,-0.5)(4,4)
CubeRow(0,0,0)CubeRow(0,0,1.1)CubeRow(0,0,2.2)
endpspicture
qquad
beginpspicture(0,-0.5)(4,4)
multidorA=-1.3+1.33multidorB=0.0+1.13CubeRow(rA,0,rB)
endpspicture

enddocument


enter image description here






share|improve this answer















Run it with pdflatex --shell-escape <file>:



documentclassarticle
usepackagepst-ob3d,pst-calculate,multido
usepackageauto-pst-pdf
defCube(#1,#2,#3)PstCube(#1,#2,#3)111
defCubeRow(#1,#2,#3)%
Cube(#1,#2,#3)Cube(#1,pscalculate#2+1.1,#3)Cube(#1,pscalculate#2+2.2,#3)
begindocument

pssetfillstyle=solid,viewpoint=0.6 0.1 0.1,fillcolor=blue!30,linecolor=blue
beginpspicture(0,-0.5)(4,2)
CubeRow(0,0,0)
endpspicture
qquad
beginpspicture(0,-0.5)(4,4)
CubeRow(0,0,0)CubeRow(0,0,1.1)CubeRow(0,0,2.2)
endpspicture
qquad
beginpspicture(0,-0.5)(4,4)
multidorA=-1.3+1.33multidorB=0.0+1.13CubeRow(rA,0,rB)
endpspicture

enddocument


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited May 8 at 14:22

























answered May 8 at 7:22









Red-CloudRed-Cloud

1,61911




1,61911












  • On my TeXLive 2019 installation this output is not obtained when compiling this with pdflatex --shell-escape <file>

    – marmot
    May 8 at 14:03

















  • On my TeXLive 2019 installation this output is not obtained when compiling this with pdflatex --shell-escape <file>

    – marmot
    May 8 at 14:03
















On my TeXLive 2019 installation this output is not obtained when compiling this with pdflatex --shell-escape <file>

– marmot
May 8 at 14:03





On my TeXLive 2019 installation this output is not obtained when compiling this with pdflatex --shell-escape <file>

– marmot
May 8 at 14:03

















draft saved

draft discarded
















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f489712%2fstacking-3d-cubes-with-spacing%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form