答案1
正如 @cfr 在评论部分所建议的那样,tikz-3dplot
这是 3D 的正确方法。建议的解决方案tikz-3dplot
是
代码如下
\documentclass[border={10}]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\tdplotsetmaincoords{70}{120} % set viewpoint
\tdplotsetrotatedcoords{0}{0}{0} %<- rotate around (z,y,z)
\begin{document}
\begin{tikzpicture}[scale=3,tdplot_rotated_coords,
rotated axis/.style={->,purple,ultra thick},
blackBall/.style={ball color = black!80},
borderBall/.style={ball color = white,opacity=.25},
very thick]
\foreach \x in {0,1,2}
\foreach \y in {0,1,2}
\foreach \z in {0,1,2}{
%#####################################################
\ifthenelse{ \lengthtest{\x pt < 2pt} }{
\draw (\x,\y,\z) -- (\x+1,\y,\z);
\shade[rotated axis,blackBall] (\x,\y,\z) circle (0.025cm);
}{}
%#####################################################
\ifthenelse{ \lengthtest{\y pt < 2pt} }{
\draw (\x,\y,\z) -- (\x,\y+1,\z);
\shade[rotated axis,blackBall] (\x,\y,\z) circle (0.025cm);
}{}
%#####################################################
\ifthenelse{ \lengthtest{\z pt < 2pt} }{
\draw (\x,\y,\z) -- (\x,\y,\z+1);
\shade[rotated axis,blackBall] (\x,\y,\z) circle (0.025cm);
}{}
}
\shade[rotated axis,blackBall] (1,0,1) circle (0.05cm);
\shade[rotated axis,blackBall] (1,2,1) circle (0.05cm);
\shade[rotated axis,blackBall] (0,1,1) circle (0.05cm);
\shade[rotated axis,blackBall] (2,1,1) circle (0.05cm);
\shade[rotated axis,blackBall] (1,1,2) circle (0.05cm);
\shade[rotated axis,blackBall] (1,1,0) circle (0.05cm);
\shade[rotated axis,borderBall] (1,0,1) circle (0.1cm);
\shade[rotated axis,borderBall] (1,2,1) circle (0.1cm);
\shade[rotated axis,borderBall] (0,1,1) circle (0.1cm);
\shade[rotated axis,borderBall] (2,1,1) circle (0.1cm);
\shade[rotated axis,borderBall] (1,1,2) circle (0.1cm);
\shade[rotated axis,borderBall] (1,1,0) circle (0.1cm);
\draw (1.1,1.15,1.05) node[scale=1.2, below] {\textbf{p}};
\end{tikzpicture}
\end{document}