[Tex/LaTex] tikz-3dplot , draw spheres instead of circles for 3D diamond lattice site visualisation

tikz-3dplottikz-pgf

This is my first actual LaTeX question, so I hope I get it right. If not, please tell me.
I've looked around, but couldn't find an answer to my question, not on stackexchange, but also not in the tikz-3dplot manual.

Problem statement

I'm using some for-loops to build a diamond lattice, whose sites I want to bi-colour with black and white spheres. In the MWE below, I've drawn a site from which the 4 nearest-neighbour links originate. In this example I use a shaded circle, to make the site look like a ball. In the example you see that the disc overwrites everything that is underneath. What I am after is to make the disc a true sphere and see at which point of the sphere the vectors are 'coming out'. The idea behind this, is to better be able to see the 3d directions.

So, to be exact, is there an analogue of the 'circle' for the tikz-3dplot, like this:

\draw (0,0,0) sphere [radius = .2 cm]; ? 

And if not, can someone point me in the right direction?

Note that manually starting my vectors at the surface of the assumed sphere, rather than at the site location (the origin in my example) could work, but since I generate a lattice of ~30 sites, this would be very tedious. Also, setting opacity so that the vectors shine through still doesn't look very spatial.

If someone wants a go or wants to be inspired, I've also put the full code for drawing the lattice in below.
directly below the output of the MWE (left) and the full code (right) (I put them on one page).
See in the MWE that the lines never overlap with the circle.

Picture

To the left the MWE, to the right the full code (axes at the bottom belong to full code)

MWE drawing the single site with bonds

\documentclass[a4paper]{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}

\tdplotsetmaincoords{70}{40} %{theta in [0,pi]}{phi in [0,2pi]}
\begin{tikzpicture}[tdplot_main_coords, scale=2]

% defining vectors s1,s2,s3,s0
\tdplotsetcoord{s1}{1}{60}{-90} 
\tdplotsetcoord{s2}{1}{60}{90} 
\tdplotsetcoord{s3}{1}{120}{180}
\tdplotsetcoord{s0}{1}{120}{0}

% setting origin to be called 'O'
\coordinate (O) at (0,0,0);

% drawing axes
\draw[thick,red,opacity=.5,->] (0,0,0) -- (2,0,0) node[anchor=north east]{$x$}; 
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,2,0) node[anchor=north west]{$y$}; 
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,0,2) node[anchor=south]{$z$};
\draw[thick,red,opacity=.25] (0,0,0) -- (-2,0,0); 
\draw[thick,red,opacity=.25] (0,0,0) -- (0,-2,0); 
\draw[thick,red,opacity=.25] (0,0,0) -- (0,0,-2);

% drawing vectors
\draw [very thick, blue,->] (O) -- ++(s1) node[anchor=south east]{$s_1$};
\draw [very thick, blue,->] (O) -- ++(s2) node[anchor=south west]{$s_2$};
\draw [very thick, blue,->] (O) -- ++(s3) node[anchor=north]{$s_3$};
\draw [very thick, blue,->] (O) -- ++(s0) node[anchor=north east]{$s_0$};

% dotted projection lines on the x-y plane
\draw [blue, dotted] (s1) -- (s1xy);
\draw [blue, dotted] (s2) -- (s2xy);
\draw [blue, dotted] (s3) -- (s3xy);
\draw [blue, dotted] (s0) -- (s0xy);

% drawing 'sphere' on the origin O
\shade[ball color=black!30!white] (0,0,0) circle (.2cm);

\end{tikzpicture}

\end{document}

II the entire document, building the lattice

\documentclass[a4paper]{standalone}
\usepackage{tikz,tikz-3dplot}
\begin{document}

\begin{center}
\tdplotsetmaincoords{60}{100} %60 130
\begin{tikzpicture}[tdplot_main_coords, scale=1]

% storing values of square roots
\pgfmathsetmacro{\N}{.85};
\pgfmathsetmacro{\Nz}{1};%{2/sqrt(3)};

% setting origin and axes
\coordinate (O) at (0,0,0); 
\draw[thick,red,opacity=.5,->] (0,0,0) -- (3,0,0) node[anchor=north east]{$x$}; 
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,3,0) node[anchor=north west]{$y$}; 
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,0,3) node[anchor=south]{$z$};
\draw[thick,red,opacity=.25] (0,0,0) -- (-3,0,0); 
\draw[thick,red,opacity=.25] (0,0,0) -- (0,-3,0); 
\draw[thick,red,opacity=.25] (0,0,0) -- (0,0,-3);

% defining s1,s2,s3,s0
\tdplotsetcoord{s1}{1}{60}{-90} 
\tdplotsetcoord{s2}{1}{60}{90} 
\tdplotsetcoord{s3}{1}{120}{180}
 \tdplotsetcoord{s0}{1}{120}{0}

% drawing axes and vectors below
\coordinate (O2) at (0,0,-10);
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (3,0,-10) node[anchor=north east]{$x$}; 
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (0,3,-10) node[anchor=north west]{$y$}; 
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (0,0,-7) node[anchor=south]{$z$};
\draw[thick,red,opacity=.25] (0,0,-10) -- (-3,0,-10); 
\draw[thick,red,opacity=.25] (0,0,-10) -- (0,-3,-10); 
\draw[thick,red,opacity=.25] (0,0,-10) -- (0,0,-13);
\draw [very thick, blue,->] (O2) -- ++(s1) node[anchor=south east]{$s_1$};
\draw [very thick, blue,->] (O2) -- ++(s2) node[anchor=south west]{$s_2$};
\draw [very thick, blue,->] (O2) -- ++(s3) node[anchor=south west]{$s_3$};
\draw [very thick, blue,->] (O2) -- ++(s0) node[anchor=north east]{$s_0$};

% drawing lattice
\foreach \a in {0,1.7}%,3.4}
\foreach \b in {0,1.5}
\foreach \c in {0,1.7}{
\draw [thick] (\a, \c, \b) -- ++(s1) node (pos1) {};
\draw [thick] (\a, \c, \b) -- ++(s2) node (pos2) {};
\draw [thick] (\a, \c, \b) -- ++(s3) node (pos3) {};
\draw [thick] (\a, \c, \b) -- ++(s0) node (pos4) {};
\draw [thick] (\a+ \N, \c+\N, \b +\Nz) -- ++(s1) node (pos5) {};
\draw [thick] (\a+ \N, \c+\N, \b+\Nz) -- ++(s2) node (pos6) {};
\draw [thick] (\a+\N, \c+\N, \b+\Nz) -- ++(s3) node (pos7) {};
\draw [thick] (\a+ \N, \c+\N, \b+\Nz) -- ++(s0) node (pos8) {};

% drawing sites
\shade[ball color=black!10!white] (pos1) circle (.1cm);
\shade[ball color=black!10!white] (pos2) circle (.1cm);
\shade[ball color=black!10!white] (pos3) circle (.1cm);
\shade[ball color=black!10!white] (pos4) circle (.1cm);
\shade[ball color=black!10!white] (pos5) circle (.1cm);
\shade[ball color=black!10!white] (pos6) circle (.1cm);
\shade[ball color=black!10!white] (pos7) circle (.1cm);
\shade[ball color=black!10!white] (pos8) circle (.1cm);
\shade[ball color=white!10!black] (\a,\c,\b) circle (.1cm);
\shade[ball color=white!10!black] (\a+\N,\c+\N,\b+\Nz) circle (.1cm);
}

\end{tikzpicture}
\end{center}

\end{document}

Best Answer

The biggest problem is that you need to draw everything from back to front in order, which isn't quite how your loop is set up. You also have some spheres almost directly behind others, confusing things somewhat.

Anyway, drawing stubs of line on top of the spheres can be done in the loop pretty easily.

\documentclass[a4paper]{standalone}
\usepackage{tikz,tikz-3dplot}
\usetikzlibrary{intersections,calc}
\begin{document}

\tdplotsetmaincoords{60}{100} %60 130
\begin{tikzpicture}[tdplot_main_coords, scale=1]

% storing values of square roots
\pgfmathsetmacro{\N}{.85};
\pgfmathsetmacro{\Nz}{1};%{2/sqrt(3)};

% setting origin and axes
\coordinate (O) at (0,0,0); 
\draw[thick,red,opacity=.5,->] (0,0,0) -- (3,0,0) node[anchor=north east]{$x$}; 
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,3,0) node[anchor=north west]{$y$}; 
\draw[thick,red,opacity=.5,->] (0,0,0) -- (0,0,3) node[anchor=south]{$z$};
\draw[thick,red,opacity=.25] (0,0,0) -- (-3,0,0); 
\draw[thick,red,opacity=.25] (0,0,0) -- (0,-3,0); 
\draw[thick,red,opacity=.25] (0,0,0) -- (0,0,-3);

% defining s1,s2,s3,s0
\tdplotsetcoord{s1}{1}{60}{-90} 
\tdplotsetcoord{s2}{1}{60}{90} 
\tdplotsetcoord{s3}{1}{120}{180}
 \tdplotsetcoord{s0}{1}{120}{0}

% sphere offsets
\tdplotsetcoord{v1}{-.1}{60}{-90}
\tdplotsetcoord{v2}{-.1}{60}{90} 
\tdplotsetcoord{v3}{-.1}{120}{180}
\tdplotsetcoord{v0}{-.1}{120}{0}

% drawing axes and vectors below
\coordinate (O2) at (0,0,-10);
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (3,0,-10) node[anchor=north east]{$x$}; 
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (0,3,-10) node[anchor=north west]{$y$}; 
\draw[thick,red,opacity=.5,->] (0,0,-10) -- (0,0,-7) node[anchor=south]{$z$};
\draw[thick,red,opacity=.25] (0,0,-10) -- (-3,0,-10); 
\draw[thick,red,opacity=.25] (0,0,-10) -- (0,-3,-10); 
\draw[thick,red,opacity=.25] (0,0,-10) -- (0,0,-13);
\draw [very thick, blue,->] (O2) -- ++(s1) node[anchor=south east]{$s_1$};
\draw [very thick, blue,->] (O2) -- ++(s2) node[anchor=south west]{$s_2$};
\draw [very thick, blue,->] (O2) -- ++(s3) node[anchor=south west]{$s_3$};
\draw [very thick, blue,->] (O2) -- ++(s0) node[anchor=north east]{$s_0$};

% drawing lattice
\foreach \a in {0,1.7}%,3.4}
\foreach \b in {0,1.5}
\foreach \c in {0,1.7}{
\draw [thick] (\a, \c, \b) -- ++(s1) coordinate (pos1);
\draw [thick] (\a, \c, \b) -- ++(s2) coordinate (pos2);
\draw [thick] (\a, \c, \b) -- ++(s3) coordinate (pos3);
\draw [thick] (\a, \c, \b) -- ++(s0) coordinate (pos4);
\draw [thick] (\a+ \N, \c+\N, \b+\Nz) -- ++(s1) coordinate (pos5);
\draw [thick] (\a+ \N, \c+\N, \b+\Nz) -- ++(s2) coordinate (pos6);
\draw [thick] (\a+\N, \c+\N, \b+\Nz) -- ++(s3) coordinate (pos7);
\draw [thick] (\a+ \N, \c+\N, \b+\Nz) -- ++(s0) coordinate (pos8);

% drawing sites
\shade[ball color=black!10!white] (pos1) circle (.1cm);
\shade[ball color=black!10!white] (pos2) circle (.1cm);
\shade[ball color=black!10!white] (pos3) circle (.1cm);
\shade[ball color=black!10!white] (pos4) circle (.1cm);
\shade[ball color=black!10!white] (pos5) circle (.1cm);
\shade[ball color=black!10!white] (pos6) circle (.1cm);
\shade[ball color=black!10!white] (pos7) circle (.1cm);
\shade[ball color=black!10!white] (pos8) circle (.1cm);
\shade[ball color=white!10!black] (\a,\c,\b) circle (.1cm);
\shade[ball color=white!10!black] (\a+\N,\c+\N,\b+\Nz) circle (.1cm);

% redraw stub lines
\draw [thick,line cap=round] ($(pos1)+(v1)$) -- ++(v1);
\draw [thick,line cap=round] ($(pos2)+(v2)$) -- ++(v2);
%\draw [thick,line cap=round] ($(pos3)+(v3)$) -- ++(v3);
\draw [thick,line cap=round] ($(pos4)+(v0)$) -- ++(v0);
\draw [thick,line cap=round] ($(pos5)+(v1)$) -- ++(v1);
\draw [thick,line cap=round] ($(pos6)+(v2)$) -- ++(v2);
%\draw [red,thick,line cap=round] ($(pos7)+(v3)$) -- ++(v3);
\draw [thick,line cap=round] ($(pos8)+(v0)$) -- ++(v0);
}

\end{tikzpicture}

\end{document}