Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How could I create a lattice like this:

10 by 10 lattice

In 3D, with the ability to change the x,y and z spacing independently of each other? Any solution using any LaTeX program would be great!

I have tried to do it with asymptote but it was a resounding failure. I can't make out the structure, see any grid, nor can I adjust the values independently.

3d lattice

Here is the code I used:

size(200);
import graph3;
import grid3;

real L=10;
triple s;
currentprojection=orthographic(0.25,0.25,0.75);
surface site = scale3(0.314)*unitsphere;

for(int i=1;i<=L;++i)
{
  for(int j=1;j<=L;++j)
  {
    for(int k=1;k<=L;++k)
    {
      s=(i,j,k);
      draw(shift(s)*site,red);
    }
  }
}
share|improve this question
    
+1: Looks good to me. Just change the view angle and maybe increase the spacing of the spheres a bit. –  Henri Menke Dec 15 '13 at 9:50
    
Heh, kinda the problem... changing the view angle is wonky in asymptote and I can't find a good one. I also can't get a grid connecting the points to work correctly with adjustable spacing. –  NictraSavios Dec 15 '13 at 9:51
    
You might be interested in dominique.vrel.free.fr/latex2.htm –  mrc Dec 15 '13 at 16:29
    
See this question: tex.stackexchange.com/questions/97271/… –  Alex Dec 15 '13 at 22:30

2 Answers 2

up vote 9 down vote accepted

Here is an example (probably inefficient, but working great !), with Tikz :

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}

\def \dx{2};
\def \dy{3};
\def \dz{2};
\def \nbx{4};
\def \nby{4};
\def \nbz{4};

\foreach \x in {1,...,\nbx} {
    \foreach \y in {1,...,\nby} {
        \foreach \z in {1,...,\nbz} {
            \node at (\x*\dx,\y*\dy,\z*\dz) [circle, fill=black] {};
        }
    }
}

% z lines
\foreach \x in {1,...,\nbx} {
    \foreach \z in {1,...,\nbz}{
        \draw (\x*\dx,\dy,\z*\dz) -- ( \x*\dx,\nby*\dy,\z*\dz);
    }
}

% x lines
\foreach \y in {1,...,\nbx} {
    \foreach \z in {1,...,\nbz}{
        \draw (\dx,\y*\dy,\z*\dz) -- ( \nbx*\dx,\y*\dy,\z*\dz);
    }
}

% y lines
\foreach \x in {1,...,\nbx} {
    \foreach \y in {1,...,\nbz}{
        \draw (\x*\dx,\y*\dy,\dz) -- ( \x*\dx,\y*\dy,\nbz*\dz);
    }
}

\end{tikzpicture}
\end{document}

enter image description here

EDIT : Here is the version with arrows, it's pretty ugly :)

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\tikzset{>=latex}

\def \dx{2};
\def \dy{3};
\def \dz{2};
\def \nbx{4};
\def \nby{4};
\def \nbz{4};

\foreach \x in {1,...,\nbx} {
    \foreach \y in {1,...,\nby} {
        \foreach \z in {1,...,\nbz} {
            \node at (\x*\dx,\y*\dy,\z*\dz) [circle, fill=black] {};
        }
    }
}

% z lines
\foreach \x in {1,...,\nbx} {
    \foreach \z in {1,...,\nbz}{
        \foreach \y in {2,...,\nby}{
            \draw [->, color = red, line width = 2pt](\x*\dx,\y*\dy - \dy,\z*\dz) -- ( \x*\dx , \y*\dy, \z*\dz);
        }
    }
}

% x lines
\foreach \y in {1,...,\nbx} {
    \foreach \z in {1,...,\nbz}{
        \foreach \x in {2,...,\nbx}{
            \draw[->, color = red, line width = 2pt](\x * \dx - \dx,\y*\dy,\z*\dz) -- ( \x * \dx,\y*\dy,\z*\dz);
        }
    }
}

% y lines
\foreach \x in {1,...,\nbx} {
    \foreach \y in {1,...,\nbz}{
        \foreach \z in {2,...,\nby}{
            \draw[->, color = red, line width = 2pt](\x*\dx,\y*\dy,\z*\dz - \dz) -- ( \x*\dx,\y*\dy,\z*\dz);
        }
    }
}

\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
1  
Your solution works great, although... if it isn't too much trouble, could you modify it to draw the lines individually? That was they can be converted to arrow to show progression from one point to the next. If its too much hassle though, don't worry! –  NictraSavios Dec 15 '13 at 11:21
1  
I'm afraid my knowledge of Tikz has already reached its limit here (I'm just starting to learn it), it looks like you're expecting an use of the animate package. I hope someone will answer it, I suggest you to edit your question. –  Thomas Dec 15 '13 at 11:25
    
Not an animation, something like what I use here in the third graphic: tex.stackexchange.com/questions/148510/… –  NictraSavios Dec 15 '13 at 11:36
    
OK I get it ! starting from (0,0,0) ? –  Thomas Dec 15 '13 at 11:47
    
Exactly!, Its related to the Metropolis Algorithm of the Ising Model. –  NictraSavios Dec 15 '13 at 13:52

Using @Tomas 's code, and adding in the arrows as per a comment, I ended up with this:

enter image description here

Code: (All credits to Thomas for the base!)

\documentclass{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
\tikzset{>=latex}

\def \dx{3};
\def \dy{3};
\def \dz{3};
\def \nbx{4};
\def \nby{4};
\def \nbz{4};

\foreach \x in {1,...,\nbx} {
    \foreach \y in {1,...,\nby} {
        \foreach \z in {1,...,\nbz} {
            \node at (\x*\dx,\y*\dy,\z*\dz) [circle, fill=red] {};
        }
    }
}

% z lines
\foreach \x in {1,...,\nbx} {
    \foreach \z in {1,...,\nbz}{
        \foreach \y in {2,...,\nby}{
            \draw [->,shorten >=0.5\dz cm,line width = 2pt]( \x*\dx , \y*\dy, \z*\dz) -- (\x*\dx,\y*\dy - \dy,\z*\dz);
        }
    }
}

% x lines
\foreach \y in {1,...,\nbx} {
    \foreach \z in {1,...,\nbz}{
        \foreach \x in {2,...,\nbx}{
            \draw[->,shorten >=0.5\dx cm, line width = 2pt](\x * \dx - \dx,\y*\dy,\z*\dz) -- ( \x * \dx,\y*\dy,\z*\dz);
        }
    }
}

% y lines
\foreach \x in {1,...,\nbx} {
    \foreach \y in {1,...,\nbz}{
        \foreach \z in {2,...,\nby}{
            \draw[->,shorten >=0.5\dy cm, line width = 2pt] ( \x*\dx,\y*\dy,\z*\dz) -- (\x*\dx,\y*\dy,\z*\dz - \dz);
        }
    }
}

\end{tikzpicture}
\end{document}
share|improve this answer
    
That's better ! ^_^ –  Thomas Dec 15 '13 at 21:29

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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