谢谢这(来自@user2478)和这(来自@user121799) 很棒的答案,我正在尝试将两者结合起来绘制一幅草图。
关键是前者和后者分别在 PSTricks 和 TikZ 中。所以,我可能应该将其中一个转换为另一个,这样组合会更直接。但不幸的是,我无法进行这样的转换。话虽如此,我有一个和pspicture
,tikzpicture
我需要移动的对象tikzpicture
,使它们进入pspicture
实体的区域。具体来说,这是到目前为止所做的。
\documentclass{article}
\usepackage{tikz}
\usepackage{pst-solides3d}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes,3d}
\begin{document}
\psset{viewpoint=10 70 15 rtp2xyz,Decran=10}
\begin{pspicture}[solidmemory](-5,-5)(6,1)
\psSolid[object=parallelepiped,a=6,b=3,c=3,RotZ=30,name=Cube,action=draw](0 0 2)
\multido{\iA=0+1}{8}{%
\psSolid[object=point,definition=solidgetsommet,args=Cube \iA]}
\psdots*[dotstyle=diamond, fillcolor=red, linecolor = red](0,2)(1,1)(0.5,0.5)(-1,1)(-2,2)(-1.5,3)(1.5,3.5)
\end{pspicture}
\psset{viewpoint=10 60 15 rtp2xyz,Decran=10}
\begin{pspicture}[solidmemory](-7.5,-5)(6,1)
\psSolid[object=parallelepiped,a=10,b=2,c=2.2,RotZ=30,name=Cube,action=draw](0 0 2)
\multido{\iA=0+1}{8}{%
\psSolid[object=point,definition=solidgetsommet,args=Cube \iA]}
\psdots*[dotstyle=diamond, fillcolor = red, linecolor = red](-2.3,2)(-1.3,1)(-1.8,0.5)(-3,1)(-4.3,2)(-3.8,3)(-0.8,3)
\psdots*[dotstyle=square, fillcolor = blue, linecolor = blue](-0.3,1)(-0.1,1.5)(0.3,2)(0.2,3)(1.5,2)(1,2.7)(0.6,1)(0.8,1.4)(1.7,2.4)(2.3,2.7)(2,1.7)
\end{pspicture}
\tdplotsetmaincoords{100}{300}
\begin{tikzpicture}[tdplot_main_coords,scale=1.1,
hexa/.style= {shape=regular polygon,regular polygon
sides=6,minimum size=1cm, draw,inner sep=0,anchor=south,rotate=30},
hexlattice/.pic={
\node[hexa] (h1;1) at ({(1-(1+pow(-1,1))*1/4)*sin(60)},{1*0.75}) {};
\node[hexa] (h1;2) at ({(1-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h1;3) at ({(1-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h2;1) at ({(2-(1+pow(-1,1))*1/4)*sin(60)},{1*0.75}) {};
\node[hexa] (h2;2) at ({(2-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h2;3) at ({(2-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h3;2) at ({(3-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
},
hexlattice2/.pic={
\node[hexa] (h0;3) at ({(0-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h1;1) at ({(1-(1+pow(-1,1))*1/4)*sin(60)},{1*0.75}) {};
\node[hexa] (h1;2) at ({(1-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h1;3) at ({(1-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h1;4) at ({(1-(1+pow(-1,4))*1/4)*sin(60)},{4*0.75}) {};
\node[hexa] (h1;5) at ({(1-(1+pow(-1,5))*1/4)*sin(60)},{5*0.75}) {};
\node[hexa] (h2;1) at ({(2-(1+pow(-1,1))*1/4)*sin(60)},{1*0.75}) {};
\node[hexa] (h2;2) at ({(2-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h2;3) at ({(2-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h2;4) at ({(2-(1+pow(-1,4))*1/4)*sin(60)},{4*0.75}) {};
\node[hexa] (h2;5) at ({(2-(1+pow(-1,5))*1/4)*sin(60)},{5*0.75}) {};
\node[hexa] (h3;1) at ({(3-(1+pow(-1,1))*1/4)*sin(60)},{1*0.75}) {};
\node[hexa] (h3;2) at ({(3-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h3;3) at ({(3-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h3;4) at ({(3-(1+pow(-1,4))*1/4)*sin(60)},{4*0.75}) {};
\node[hexa] (h3;5) at ({(3-(1+pow(-1,5))*1/4)*sin(60)},{5*0.75}) {};
\node[hexa] (h4;2) at ({(4-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h4;3) at ({(4-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h4;4) at ({(4-(1+pow(-1,4))*1/4)*sin(60)},{4*0.75}) {};
}]
\begin{scope}[canvas is xz plane at y=0,transform shape]
\pic[scale=1.1] at (5,0) {hexlattice};
\end{scope}
\begin{scope}[canvas is xz plane at y=0,transform shape]
\pic[scale=0.6] at (0,0) {hexlattice2};
\end{scope}
\end{tikzpicture}
\end{document}
我需要将每个小蜂窝向上移动到它们对应的立方体的正前方,如下所示。
但是,我越是纠结于这些数值scope
,就越是无法接近我想要的结果!
实现这种转变的最佳解决方法是什么?
答案1
这回答了在技术层面上如何做到这一点的问题。这很容易:添加一个tikzmark
with \rput
,然后使用overlay, remember picture
添加图片。
\documentclass{article}
\usepackage{tikz}
\usepackage{pst-solides3d}
\usepackage{tikz-3dplot}
\usetikzlibrary{shapes,3d,tikzmark}
\begin{document}
\psset{viewpoint=10 70 15 rtp2xyz,Decran=10}
\begin{pspicture}[solidmemory](-5,-5)(6,1)
\psSolid[object=parallelepiped,a=6,b=3,c=3,RotZ=30,name=Cube,action=draw](0 0 2)
\multido{\iA=0+1}{8}{%
\psSolid[object=point,definition=solidgetsommet,args=Cube \iA]}
\psdots*[dotstyle=diamond, fillcolor=red, linecolor = red](0,2)(1,1)(0.5,0.5)(-1,1)(-2,2)(-1.5,3)(1.5,3.5)
\rput(-5,-3.5){\tikzmark{x1}}
\end{pspicture}
\psset{viewpoint=10 60 15 rtp2xyz,Decran=10}
\begin{pspicture}[solidmemory](-7.5,-5)(6,1)
\psSolid[object=parallelepiped,a=10,b=2,c=2.2,RotZ=30,name=Cube,action=draw](0 0 2)
\multido{\iA=0+1}{8}{%
\psSolid[object=point,definition=solidgetsommet,args=Cube \iA]}
\psdots*[dotstyle=diamond, fillcolor = red, linecolor = red](-2.3,2)(-1.3,1)(-1.8,0.5)(-3,1)(-4.3,2)(-3.8,3)(-0.8,3)
\psdots*[dotstyle=square, fillcolor = blue, linecolor = blue](-0.3,1)(-0.1,1.5)(0.3,2)(0.2,3)(1.5,2)(1,2.7)(0.6,1)(0.8,1.4)(1.7,2.4)(2.3,2.7)(2,1.7)
\rput(-7.5,-3.5){\tikzmark{x2}}
\end{pspicture}
\tdplotsetmaincoords{100}{300}
\begin{tikzpicture}[tdplot_main_coords,scale=1.1,
hexa/.style= {shape=regular polygon,regular polygon
sides=6,minimum size=1cm, draw,inner sep=0,anchor=south,rotate=30},
hexlattice/.pic={
\node[hexa] (h1;1) at ({(1-(1+pow(-1,1))*1/4)*sin(60)},{1*0.75}) {};
\node[hexa] (h1;2) at ({(1-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h1;3) at ({(1-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h2;1) at ({(2-(1+pow(-1,1))*1/4)*sin(60)},{1*0.75}) {};
\node[hexa] (h2;2) at ({(2-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h2;3) at ({(2-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h3;2) at ({(3-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
},
hexlattice2/.pic={
\node[hexa] (h0;3) at ({(0-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h1;1) at ({(1-(1+pow(-1,1))*1/4)*sin(60)},{1*0.75}) {};
\node[hexa] (h1;2) at ({(1-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h1;3) at ({(1-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h1;4) at ({(1-(1+pow(-1,4))*1/4)*sin(60)},{4*0.75}) {};
\node[hexa] (h1;5) at ({(1-(1+pow(-1,5))*1/4)*sin(60)},{5*0.75}) {};
\node[hexa] (h2;1) at ({(2-(1+pow(-1,1))*1/4)*sin(60)},{1*0.75}) {};
\node[hexa] (h2;2) at ({(2-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h2;3) at ({(2-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h2;4) at ({(2-(1+pow(-1,4))*1/4)*sin(60)},{4*0.75}) {};
\node[hexa] (h2;5) at ({(2-(1+pow(-1,5))*1/4)*sin(60)},{5*0.75}) {};
\node[hexa] (h3;1) at ({(3-(1+pow(-1,1))*1/4)*sin(60)},{1*0.75}) {};
\node[hexa] (h3;2) at ({(3-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h3;3) at ({(3-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h3;4) at ({(3-(1+pow(-1,4))*1/4)*sin(60)},{4*0.75}) {};
\node[hexa] (h3;5) at ({(3-(1+pow(-1,5))*1/4)*sin(60)},{5*0.75}) {};
\node[hexa] (h4;2) at ({(4-(1+pow(-1,2))*1/4)*sin(60)},{2*0.75}) {};
\node[hexa] (h4;3) at ({(4-(1+pow(-1,3))*1/4)*sin(60)},{3*0.75}) {};
\node[hexa] (h4;4) at ({(4-(1+pow(-1,4))*1/4)*sin(60)},{4*0.75}) {};
},overlay,remember picture]
\begin{scope}[canvas is xz plane at y=0,transform shape]
\pic[scale=1.1] at ([xshift=-5.5cm,yshift=-1.2cm]pic cs:x1) {hexlattice};
\end{scope}
\begin{scope}[canvas is xz plane at y=0,transform shape]
\pic[scale=0.6] at ([xshift=-9cm,yshift=-1cm]pic cs:x2) {hexlattice2};
\end{scope}
\end{tikzpicture}
\end{document}
然而,我想说的是,你会方式如果你只是用perspective
如果你用Ti 库钾Z. 这是一个开始。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{perspective}
\begin{document}
\begin{tikzpicture}[3d view,%
perspective,
pics/hexlattice cell/.style={code={
\def\pv##1{\pgfkeysvalueof{/tikz/hexlattice/##1}}
\tikzset{hexlattice/.cd,#1}
\draw (tpp cs:x={\pv{x}},y={\pv{y}+\pv{a}*cos(0+\pv{phi})},z={\pv{z}+\pv{a}*sin(0+\pv{phi})})
foreach \YY in {60,120,...,300}
{-- (tpp cs:x={\pv{x}},y={\pv{y}+\pv{a}*cos(\YY+\pv{phi})},z={\pv{z}+\pv{a}*sin(\YY+\pv{phi})})}
-- cycle; }},
pics/hexlattice/.style={code={
\def\pv##1{\pgfkeysvalueof{/tikz/hexlattice/##1}}
\tikzset{hexlattice/.cd,#1}
\ifcase\pv{N}
\or
\pic{hexlattice cell={x=\pv{X},y=\pv{Y},z=\pv{Z}}};
\or
\path pic{hexlattice cell={x=\pv{X},y=\pv{Y},z=\pv{Z}}}
foreach \XX in {0,60,...,300}
{pic{hexlattice cell={x={\pv{X}},
y={\pv{Y}+2*cos(30)*\pv{a}*cos(30+\XX+\pv{phi})},
z={\pv{Z}+2*cos(30)*\pv{a}*sin(30+\XX+\pv{phi})}}}};
\or
\path pic{hexlattice cell={x=\pv{X},y=\pv{Y},z=\pv{Z}}}
foreach \XX in {0,60,...,300}
{pic{hexlattice cell={x={\pv{X}},
y={\pv{Y}+2*cos(30)*\pv{a}*cos(30+\XX+\pv{phi})},
z={\pv{Z}+2*cos(30)*\pv{a}*sin(30+\XX+\pv{phi})}}}
pic{hexlattice cell={x={\pv{X}},
y={\pv{Y}+2*(1+sin(30))*\pv{a}*cos(\XX+\pv{phi})},
z={\pv{Z}+2*(1+sin(30))*\pv{a}*sin(\XX+\pv{phi})}}}
};
\or
\path pic{hexlattice cell={x=\pv{X},y=\pv{Y},z=\pv{Z}}}
foreach \XX in {0,60,...,300}
{pic{hexlattice cell={x={\pv{X}},
y={\pv{Y}+2*cos(30)*\pv{a}*cos(30+\XX+\pv{phi})},
z={\pv{Z}+2*cos(30)*\pv{a}*sin(30+\XX+\pv{phi})}}}
pic{hexlattice cell={x={\pv{X}},
y={\pv{Y}+2*(1+sin(30))*\pv{a}*cos(\XX+\pv{phi})},
z={\pv{Z}+2*(1+sin(30))*\pv{a}*sin(\XX+\pv{phi})}}}
pic{hexlattice cell={x={\pv{X}},
y={\pv{Y}+4*cos(30)*\pv{a}*cos(30+\XX+\pv{phi})},
z={\pv{Z}+4*cos(30)*\pv{a}*sin(30+\XX+\pv{phi})}}}
};
\fi
}},
hexlattice/.cd,a/.initial=1,x/.initial=0,y/.initial=0,z/.initial=0,
X/.initial=0,Y/.initial=0,Z/.initial=0,
N/.initial=1,phi/.initial=0]
\draw[dashed] (tpp cs:x=10,y=-2,z=4) -- (tpp cs:x=10,y=2,z=4)
-- (tpp cs:x=00,y=2,z=4);
\draw[dashed] (tpp cs:x=10,y=-2,z=0) -- (tpp cs:x=10,y=2,z=0)
-- (tpp cs:x=00,y=2,z=0);
\draw[dashed] (tpp cs:x=10,y=2,z=4) -- (tpp cs:x=10,y=2,z=0);
\draw (tpp cs:x=0,y=-2,z=0) -- (tpp cs:x=0,y=2,z=0)
-- (tpp cs:x=0,y=2,z=4) -- (tpp cs:x=0,y=-2,z=4) -- cycle;
\draw (tpp cs:x=0,y=-2,z=4) -- (tpp cs:x=10,y=-2,z=4)
-- (tpp cs:x=10,y=-2,z=0) -- (tpp cs:x=0,y=-2,z=0) -- cycle;
\pic{hexlattice={N=4,phi=30,a=0.4,Z=2}};
\end{tikzpicture}
\end{document}