# Drawing 3D lattice using TikZ

I need to draw 3D grid with nodes on it using Tikz. Moreover, would it be possible to construct it simply by 3 nested loops? So that I could mark some node by hollow circle and some with solid circle... The viewpoint is also important for visual clarity.

The linked duplicate have a lot of new command and setting a lot of macros. It should not be that complicated. I want to do it with basic instruction set so that code would remain easy to understand; and easy to recall...

The other difference is that only selected nodes will be marked with solid circle, not all the nodes. The above linked answer does not help in this regard either...

• The more complicated something is, the more complicated it is to visualize. Why do you expect an easy solution? – Johannes_B Jul 16 '17 at 13:52
• Apparently you expect, that some one will draw this image instead you ... it is not like to happen. From link you had provided, you can compose some own code and ask for help where you stuck. – Zarko Jul 16 '17 at 14:41
• You don't even provide the link which you mention. So anybody who wants to help you must start absolutely from scratch. tikz-3dplot might help. Or you can just use the standard coordinate system. Not really clear now what is too complicated, how you want to use the loops or what the problem is you're having. – cfr Jul 16 '17 at 15:23
• Please consider accepting one of the answers to your earlier question if it solved the problem satisfactorily. – cfr Jul 16 '17 at 20:25

As suggested by @cfr in the comments section, tikz-3dplot is the way to go when it comes to 3D. A suggested solution by tikz-3dplot is

The code is

\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);
}{}
%#####################################################
\ifthenelse{  \lengthtest{\y pt < 2pt}  }{
\draw (\x,\y,\z) -- (\x,\y+1,\z);
}{}
%#####################################################
\ifthenelse{  \lengthtest{\z pt < 2pt}  }{
\draw (\x,\y,\z) -- (\x,\y,\z+1);
}{}

}