間隔を空けて3Dキューブを積み重ねる
Stacking 3d Cubes With Spacing
解決:
これはあなたにスタートを与えることです。私は基本的に、この回答のコードをリサイクルして少し変更しました。これらの定義により、ベクトルの描画は次のように簡単になります。
path pic {cube array = {num cubes x = 3}};あなた:
documentclass [tikz、border = 3.14mm] {standalone} usepackage {tikz-3dplot} usetikzlibrary {calc} tikzset {plane / .style n args = {3} {insert path = {%#1-++ #2-++#3-++($ -1 *#2 $)-サイクル}}、単位xy平面/.style={plane={#1}{(1,0,0)} {(0,1,0)}}、単位xz平面/.style= {平面= {#1} {(1,0,0)} {(0,0,1)}}、単位yz平面/。 style = {plane = {#1} {(0,1,0)} {(0,0,1)}}、getprojections / .style = {insert path = {%let p1 =(1,0、 0)、 p2 =(0,1,0)in [/ utils / exec = { pgfmathtruncatemacro { xproj} {sign( x1)} xdef xproj { xproj} pgfmathtruncatemacro { yproj} {sign ( x2)} xdef yproj { yproj} pgfmathtruncatemacro { zproj} {sign(cos( tdplotmaintheta))} xdef zproj { zproj}}]}}、pics / unit cube / .style = {code = { path [get Projections]; draw(0,0,0)-(1,1,1); ifnum zproj = -1 path [3dキューブ/すべての面、3dキューブ/ xy面、ユニットxy平面= {(0,0,0)}]; fi ifnum yproj = 1 path [3dキューブ/すべての面、3dキューブ/ yz面、ユニットyz平面= {(1,0,0)}]; else path [3dキューブ/すべての面、3dキューブ/ yz面、ユニットyz平面= {(0,0,0)}]; fi ifnum xproj = 1 path [3dキューブ/すべての面、3dキューブ/ xz面、ユニットxz平面= {(0,0,0)}]; else path [3dキューブ/すべての面、3dキューブ/ xz面、ユニットxz平面= {(0,1,0)}]; fi ifnum zproj> -1 path [3dキューブ/すべての面、3dキューブ/ xy面、ユニットxy平面= {(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 thin}、/ tikz / pics / .cd、cube array / .style = {code = {% tikzset {3d cube / .cd、#1}% typeout { NumCubesX、 NumCubesY、 NumCubesZ} path [get Projections]; ifnum yproj = 1 def LstX {1、...、 NumCubesX} else ifnum NumCubesX> 1 pgfmathtruncatemacro { NextToLast} { NumCubesX-1} def LstX { NumCubesX、 NextToLast 、...、1} else def LstX {1} fi fi ifnum xproj = -1 def LstY {1、...、 NumCubesY} else ifnum NumCubesY> 1 pgfmathtruncatemacro { NextToLast} { NumCubesX-1} def LstY { NumCubesY、 NextToLast、...、1} else def LstY {1} fi fi ifnum zproj = 1 def LstZ {1、...、 NumCubesZ} else ifnum NumCubesZ> 1 pgfmathtruncatemacro { NextToLast} { NumCubesX-1} def LstZ { NumCubesZ、 NextToLast、...、1} else def LstZ {1} fi def LstZ { NumCubesZ、 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キューブ/キューブスケール}] {unit cube};}}}}}} begin {document} tdplotsetmaincoords {60} {200}%最初の引数は90より大きくすることはできません begin {tikzpicture} [line join = round、font = sffamily 、3d cube / .cd、num cubes x = 1、num cubes y = 1、num cubes z = 1] begi n {scope} [local bounding box = first row] begin {scope} [tdplot_main_coords、local bounding box = vector] path pic {cube array = {num cubes x = 3}}; end {scope} begin {scope} [xshift = 4cm、tdplot_main_coords、local bounding box = matrix] path pic {cube array = {num cubes x = 3、num cubes z = 3}}; end {scope} begin {scope} [xshift = 8cm、tdplot_main_coords、local bounding box = array] path pic {cube array = {num cubes x = 3、num cubes y = 3、num cubes z = 3}} ; end {scope} end {scope} foreach X in {vector、matrix、array} { node [above] at( X | -first row.north){ X};}% begin {scope } [yshift = -5.5cm、local bounding box = data frame、tdplot_main_coords] foreach Col [count = XX] in {blue、purple、green} { path(2- XX、0,0)pic { cube array = {num cubes z = 3、xy face / .style = {fill = Col!10}、xz face / .style = {fill = Col!20}、yz face / .style = {fill = Col!30}}};} end {scope} node [above](df)at(data frame.north){data frame}; % begin {scope} [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}}}; end {scope} node at(df- | more){more}; end {tikzpicture} end {document}
ビューは自由に調整できます。
documentclass [tikz、border = 3.14mm] {standalone} usepackage {tikz-3dplot} usetikzlibrary {calc} tikzset {plane / .style n args = {3} {insert path = {%#1-++ #2-++#3-++($ -1 *#2 $)-サイクル}}、単位xy平面/.style={plane={#1}{(1,0,0)} {(0,1,0)}}、単位xz平面/.style= {平面= {#1} {(1,0,0)} {(0,0,1)}}、単位yz平面/。 style = {plane = {#1} {(0,1,0)} {(0,0,1)}}、getprojections / .style = {insert path = {%let p1 =(1,0、 0)、 p2 =(0,1,0)in [/ utils / exec = { pgfmathtruncatemacro { xproj} {sign( x1)} xdef xproj { xproj} pgfmathtruncatemacro { yproj} {sign ( x2)} xdef yproj { yproj} pgfmathtruncatemacro { zproj} {sign(cos( tdplotmaintheta))} xdef zproj { zproj}}]}}、pics / unit cube / .style = {code = { path [get Projections]; draw(0,0,0)-(1,1,1); ifnum zproj = -1 path [3dキューブ/すべての面、3dキューブ/ xy面、ユニットxy平面= {(0,0,0)}]; fi ifnum yproj = 1 path [3dキューブ/すべての面、3dキューブ/ yz面、ユニットyz平面= {(1,0,0)}]; else path [3dキューブ/すべての面、3dキューブ/ yz面、ユニットyz平面= {(0,0,0)}]; fi ifnum xproj = 1 path [3dキューブ/すべての面、3dキューブ/ xz面、ユニットxz平面= {(0,0,0)}]; else path [3dキューブ/すべての面、3dキューブ/ xz面、ユニットxz平面= {(0,1,0)}]; fi ifnum zproj> -1 path [3dキューブ/すべての面、3dキューブ/ xy面、ユニットxy平面= {(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 thin}、/ tikz / pics / .cd、cube array / .style = {code = {% tikzset {3d cube / .cd、#1}% typeout { NumCubesX、 NumCubesY、 NumCubesZ} path [get Projections]; ifnum yproj = 1 def LstX {1、...、 NumCubesX} else ifnum NumCubesX> 1 pgfmathtruncatemacro { NextToLast} { NumCubesX-1} def LstX { NumCubesX、 NextToLast 、...、1} else def LstX {1} fi fi ifnum xproj = -1 def LstY {1、...、 NumCubesY} else ifnum NumCubesY> 1 pgfmathtruncatemacro { NextToLast} { NumCubesX-1} def LstY { NumCubesY、 NextToLast、...、1} else def LstY {1} fi fi ifnum zproj = 1 def LstZ {1、...、 NumCubesZ} else ifnum NumCubesZ> 1 pgfmathtruncatemacro { NextToLast} { NumCubesX-1} def LstZ { NumCubesZ、 NextToLast、...、1} else def LstZ {1} fi def LstZ { NumCubesZ、 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キューブ/キューブスケール}] {unit cube};}}}}}} begin {document} foreach Angle in {5,15、...、355} { tdplotsetmaincoords {60} { Angle}%最初の引数を指定することはできません90より大きい begin {tikzpicture} [line join = round、font = sffamily、3d cube / .cd、num cubes x = 1、num cubes y = 1、num cubes z = 1] path [バウンディングボックスとして使用](-3、-3)長方形(12,4); begin {scope} [ローカルバウンディングボックス=最初の行] begin {scope} [tdplot_main_coords、ローカルバウンディングボックス=ベクトル] path pic {cube array = {num cubes x = 3}}; end {scope} begin {scope} [xshift = 4cm、tdplot_main_coords、local bounding box = matrix] path pic {cube array = {num cubes x = 3、num cubes z = 3}}; end {scope} begin {scope} [xshift = 8cm、tdplot_main_coords、local bounding box = array] path pic {cube array = {num cubes x = 3、num cubes y = 3、num cubes z = 3}} ; end {scope} end {scope} foreach X in {vector、matrix、array} { node [below] at( X | -first row.north){ X};} end {tikzpicture} } end {document}
で実行するpdflatex --shell-escape:
documentclass {article} usepackage {pst-ob3d、pst-calculate、multido} usepackage {auto-pst-pdf} def Cube(#1、#2、#3){ PstCube(#1、#2 、#3){1} {1} {1}} def CubeRow(#1、#2、#3){% Cube(#1、#2、#3) Cube(#1、 pscalculate {#2 + 1.1}、#3) Cube(#1、 pscalculate {#2 + 2.2}、#3)} begin {document} psset {fillstyle = solid、viewpoint = 0.6 0.1 0.1、fillcolor = blue !30、linecolor = blue} begin {pspicture}(0、-0.5)(4,2) CubeRow(0,0,0) end {pspicture} qquad begin {pspicture}(0、-0.5) (4,4) CubeRow(0,0,0) CubeRow(0,0,1.1) CubeRow(0,0,2.2) end {pspicture} qquad begin {pspicture}(0、-0.5) (4,4) multido { rA = -1.3 + 1.3} {3} { multido { rB = 0.0 + 1.1} {3} { CubeRow( rA、0、 rB)}} end { pspicture} end {document}