# Help creating solid cylinders along a path in Tikz for crystal lattice diagram

I am trying to draw a diagram using Tikz that will show the crystalline lattice structure of diamond. It should look like the following illustration (reference).

I have managed to figure out the locations of each of the carbon atoms. I defined each of those locations as a coordinate (A, B, ... Q) and I managed to draw the atoms, but I don't like the look of the lines that show which atoms are connected.

My problem is that the lines are not distinct enough from one another. Instead of plain lines I would like to draw three dimensional cylinders that connect the atoms together as I think that would make the image look much better. I have no idea how to get Tikz to do this, however.

Here's what I've got so far. Anybody have an idea?

\documentclass[10pt]{article}
\usepackage{tikz}
\begin{document}
\pagestyle{empty}

\begin{tikzpicture}[scale = 1]

%points on cube

\coordinate (A) at (0,0,0);
\coordinate (B) at (0,0,4);
\coordinate (D) at (0,4,0);
\coordinate (C) at (0,4,4);
\coordinate (E) at (4,0,0);
\coordinate (F) at (4,0,4);
\coordinate (H) at (4,4,0);
\coordinate (G) at (4,4,4);

%center of faces

\coordinate (I) at (0,2,2); %center of face ABCD
\coordinate (J) at (4,2,2); %center of face EFGH
\coordinate (K) at (2,4,2); %center of face DCGH
\coordinate (L) at (2,0,2); %center of face ABFE
\coordinate (M) at (2,2,4); %center of face CBGF
\coordinate (N) at (2,2,0); %center of face DAEH

%connectors

\coordinate (O) at (1,1,3);
\coordinate (P) at (1,3,1);
\coordinate (Q) at (3,1,1);
\coordinate (R) at (3,3,3);
%place non-atom cube corners
\shadedraw [ball color= gray] (A) circle (0.1cm);
\shadedraw [ball color= gray] (C) circle (0.1cm);
\shadedraw [ball color= gray] (F) circle (0.1cm);
\shadedraw [ball color= gray] (H) circle (0.1cm);
\shadedraw [ball color= black] (B) circle (0.25cm);
\shadedraw [ball color= black] (D) circle (0.25cm);
\shadedraw [ball color= black] (E) circle (0.25cm);
\shadedraw [ball color= black] (G) circle (0.25cm);
%draw the center of each face
\shadedraw [ball color= red] (I) circle (0.25cm);
\shadedraw [ball color= red] (J) circle (0.25cm);
\shadedraw [ball color= red] (K) circle (0.25cm);
\shadedraw [ball color= red] (L) circle (0.25cm);
\shadedraw [ball color= red] (M) circle (0.25cm);
\shadedraw [ball color= red] (N) circle (0.25cm);
%connectors
\shadedraw [ball color= blue] (O) circle (0.25cm);
\shadedraw [ball color= blue] (P) circle (0.25cm);
\shadedraw [ball color= blue] (Q) circle (0.25cm);
\shadedraw [ball color= blue] (R) circle (0.25cm);
%draw cube
\draw [dashed] (A) -- (B);
\draw [dashed] (B) -- (C);
\draw [dashed] (C) -- (D);
\draw [dashed] (D) -- (A);
\draw [dashed] (E) -- (F);
\draw [dashed] (F) -- (G);
\draw [dashed] (G) -- (H);
\draw [dashed] (H) -- (E);
\draw [dashed] (A) -- (E);
\draw [dashed] (B) -- (F);
\draw [dashed] (C) -- (G);
\draw [dashed] (D) -- (H);
%connections from faces to O
\draw [very thick] (B) -- (O);
\draw [very thick] (I) -- (O);
\draw [very thick] (M) -- (O);
\draw [very thick] (L) -- (O);
%connections from faces to P
\draw [very thick] (N) -- (P);
\draw [very thick] (I) -- (P);
\draw [very thick] (D) -- (P);
\draw [very thick] (K) -- (P);
%connections from faces to Q
\draw [very thick] (E) -- (Q);
\draw [very thick] (J) -- (Q);
\draw [very thick] (N) -- (Q);
\draw [very thick] (L) -- (Q);
%connections from faces to R
\draw [very thick] (G) -- (R);
\draw [very thick] (M) -- (R);
\draw [very thick] (J) -- (R);
\draw [very thick] (K) -- (R);
\end{tikzpicture}
\end{document}

-
Possible duplicate here. – kiss my armpit May 17 '13 at 17:00
Welcome to TeX.sx! Feel free to visit our TeX.SX starter guide to get the most out of our site. – Peter Jansson May 17 '13 at 17:22
The lines in the linked page do seem fairly two-dimensional, so maybe just a thicker line width or “tapered” lines like in Drawing Tapered Edges in Graph? – Qrrbrbirlbel May 17 '13 at 18:25
Here's another crystal lattice question tex.stackexchange.com/questions/97271/… – Alex May 17 '13 at 18:44
You might also be interested in a similar answer tex.stackexchange.com/questions/141363/… – strpeter Jan 21 '14 at 21:42

This model uses cylinders for connection, rendered in Asymptote, cr.asy:

size(300);
import solids;

currentprojection=orthographic (
camera=(8,5,4),
up=(0,0,1),
target=(2,2,2),
zoom=0.5
);

// save predefined 2D orientation vectors
pair NN=N;
pair SS=S;
pair EE=E;
pair WW=W;

//%points on cube

triple A = (0,0,0);
triple B = (0,0,4);
triple D = (0,4,0);
triple C = (0,4,4);
triple E = (4,0,0);
triple F = (4,0,4);
triple H = (4,4,0);
triple G = (4,4,4);

triple[] cubicCornerA={
A,C,F,H,
};

triple[] cubicCornerB={
B,D,E,G,
};

//%center of faces

triple I = (A+B+C+D)/4; //%center of face ABCD
triple J = (E+F+G+H)/4; //%center of face EFGH
triple K = (D+C+G+H)/4; //%center of face DCGH
triple L = (A+B+F+E)/4; //%center of face ABFE
triple M = (C+B+G+F)/4; //%center of face CBGF
triple N = (D+A+E+H)/4; //%center of face DAEH

triple[] faceCenter={
I,J,K,L,M,N,
};

//%connectors
triple O = (1,1,3);
triple P = (1,3,1);
triple Q = (3,1,1);
triple R = (3,3,3);

triple[] connectors={
O,P,Q,R,
};

//%place non-atom cube corners

real cornerAR=0.05;
real cornerBR=0.2;
real faceCR=0.2;
real connR=faceCR;

draw(A--B--C--D--cycle,dashed);
draw(E--F--G--H--cycle,dashed);
draw(A--E,dashed);
draw(B--F,dashed);
draw(C--G,dashed);
draw(D--H,dashed);

real cylR=0.062;

void Draw(guide3 g,pen p=currentpen){
draw(
cylinder(
point(g,0),cylR,arclength(g),point(g,1)-point(g,0)
).surface(
new pen(int i, real j){
return p;
}
)
);
}

//%connections from faces to O
pen connectPen=lightgray;
Draw(B--O,connectPen);
Draw(I--O,connectPen);
Draw(M--O,connectPen);
Draw(L--O,connectPen);

//%connections from faces to P
Draw(N--P,connectPen);
Draw(I--P,connectPen);
Draw(D--P,connectPen);
Draw(K--P,connectPen);

//%connections from faces to Q
Draw(E--Q,connectPen);
Draw(J--Q,connectPen);
Draw(N--Q,connectPen);
Draw(L--Q,connectPen);

//%connections from faces to R
Draw(G--R,connectPen);
Draw(M--R,connectPen);
Draw(J--R,connectPen);
Draw(K--R,connectPen);

void drawSpheres(triple[] C, real R, pen p=currentpen){
for(int i=0;i<C.length;++i){
draw(sphere(C[i],R).surface(
new pen(int i, real j){return p;}
)
);
}
}

drawSpheres(cubicCornerA,cornerAR,lightgray);
drawSpheres(cubicCornerB,cornerBR,darkgray);
drawSpheres(faceCenter,faceCR,red);
drawSpheres(connectors,connR,lightblue);


Process with asy -f pdf cr.asy to get an interactive (Adobe Reader only) standalone cr.pdf, or with asy -f pdf -noprc -render=0 cr.asy to get an ordinary cr.pdf, or asy -f png -render=5 cr.asy to get a smaller raster image cr.png.

-
Brilliant! That is exactly what I'm looking for! – shane May 18 '13 at 18:25
The original image uses grey dashed lines for the edges of the cube that lie behind the cube, and I think that makes it a little easier for the eye to organize the image. – Benjamin McKay Jun 26 '13 at 14:03
But at the same time, the result is much clearer than the original, because of the colours of the nodes, and the shading of the cylinders, so hats off. – Benjamin McKay Jun 26 '13 at 14:04
@Benjamin McKay: The colors are easy to change, see the answer to Labels and angles in crystal structure using Asymptote. – g.kov Jun 26 '13 at 16:13
@g.kov That's very beautiful. I'm quite a fan of your asymptote solutions :). Unfortunately, I have a little bit of trouble reproducing this one in its full glory when I compile it with asy -f pdf -noprc -render=0 cr.asy. In this case, the lighting and the colors don't look so nice anymore, the spheres have some defects at their tops and the z-ordering gets confused, e.g. the backmost (red) sphere is in the front of the picture and most of the bond-atom-orderings are broken. Is this a general problem or is it only me who experiences this (I'm working with Windows 7 64bit, Asymptote 2.23)? – Philipp Jul 1 '13 at 23:50