6
$\begingroup$
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?

$\endgroup$
1

2 Answers 2

5
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Is there a way in which i can connect those dots and replace the dots by spheres. $\endgroup$
    – PyariBilli
    Feb 6, 2013 at 16:37
  • $\begingroup$ @gforce89 Yes. Just use Sphere[#, radius]& in place of Point. For the lines you need to generate a 2D grid for each face. $\endgroup$
    – Szabolcs
    Feb 6, 2013 at 16:38
  • 2
    $\begingroup$ 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] $\endgroup$
    – PyariBilli
    Feb 6, 2013 at 16:42
12
$\begingroup$

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

$\endgroup$
5
  • $\begingroup$ 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. $\endgroup$
    – PyariBilli
    Feb 6, 2013 at 16:51
  • $\begingroup$ Very nice, +1. It would be even nicer to remove the faces of the cube, if easily possible. $\endgroup$
    – Szabolcs
    Feb 7, 2013 at 0:21
  • $\begingroup$ @Szabolcs thanks, your comment convinced me to do some work on this ;) $\endgroup$ Feb 7, 2013 at 1:57
  • $\begingroup$ @gforce89 improved. $\endgroup$ Feb 7, 2013 at 1:59
  • 1
    $\begingroup$ It got interesting when you started putting others kinds of cells in the lattice :) $\endgroup$
    – Szabolcs
    Feb 7, 2013 at 3:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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