Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.
LatticeData["SimpleCubic", "Image"] 

The above line gives me a single cube (2 lattice points in each direction).

But I want a lattice with 4 lattice points in each direction. How do I generate that?

share|improve this question
    
related Q/A: How to make a 3D grid –  kguler Feb 6 '13 at 16:39

2 Answers 2

up vote 2 down vote accepted

It is easy to generate coordinates for these using Tuples:

coords = Tuples[Range[4], 3]

Graphics3D@Point[coords]

Mathematica graphics

If you need the grid lines too, you can generate a 2D lattice for each face in a similar way and extrude them into lines.

share|improve this answer
    
Is there a way in which i can connect those dots and replace the dots by spheres. –  gforce89 Feb 6 '13 at 16:37
    
@gforce89 Yes. Just use Sphere[#, radius]& in place of Point. For the lines you need to generate a 2D grid for each face. –  Szabolcs Feb 6 '13 at 16:38
2  
what i finally used was this : tpls = Tuples[Range[4], 3]; lines3 = Table[Partition[RotateRight[#, k] & /@ tpls, 4], {k, 0, 2}]; Graphics3D[{{RGBColor[#], Sphere[#, 1/10]} & /@ tpls, Tube /@ lines3}, Boxed -> False] –  gforce89 Feb 6 '13 at 16:42

The comments I got for this post are about speed basically. I improved it greatly because I removed opacity objects (which are nice visually but cause slow down). So let me just show the final result of fast and much more complicated (Tetrahedral) lattice than yours (which means your simple cubic will work too but with a bonus). So get your data

cell = LatticeData["TetrahedralPacking", "Image"];

Build extended lattice:

Graphics3D[Translate[DeleteCases[cell, {_, _, Polygon[_]}, Infinity][[1]], 
  2 Tuples[Range[3], 3]], Boxed -> False]

enter image description here

Now, let me go back in time and explain from the very beginning how it works. A brute force approach. Here is a single lattice cell:

cell = LatticeData["SimpleCubic", "Image"];

Now use Translate:

Graphics3D[Translate[cell[[1]], 2 Tuples[Range[4], 3]], Boxed -> False]

enter image description here

Even so the method is a bit wasteful (you repeating overlapping spheres), it is very simple and works for much more complicated crystal structures where creating custom grid is tedious - plus the style of lattice data is nice:

cell = LatticeData["TetrahedralPacking", "Image"]

enter image description here

Graphics3D[Translate[cell[[1]], 2 Tuples[Range[2], 3]], Boxed -> False]

enter image description here

share|improve this answer
    
This is good but it takes to much time to compute and animation is very slow. The tuples method as suggested by @Szabolcs is very fast. –  gforce89 Feb 6 '13 at 16:51
    
Very nice, +1. It would be even nicer to remove the faces of the cube, if easily possible. –  Szabolcs Feb 7 '13 at 0:21
    
@Szabolcs thanks, your comment convinced me to do some work on this ;) –  Vitaliy Kaurov Feb 7 '13 at 1:57
    
@gforce89 improved. –  Vitaliy Kaurov Feb 7 '13 at 1:59
1  
It got interesting when you started putting others kinds of cells in the lattice :) –  Szabolcs Feb 7 '13 at 3:07

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.