2

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...

enter image description here

  • 2
    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
  • 1
    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
5

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

enter image description here

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);
             \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}
  • That's wonderful. Now I can work out different pictures based on this example. But why do we require using the rotated axis with shade?... We have already rotated the system before we begin the picture tikz... Moreover if we want to shade a particular plane in a light gray, say, the plane containing p, and the border balls in the picture. There are two such planes here. Suppose we want to shade the vertical plane. Should I rotate axis for this as well? Thanks... – madeel Jul 17 '17 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.