6
$\begingroup$

We can construct a base-centered tetragonal unit cell by:

LatticeData["CenteredTetragonal", "Image"]

But how can we construct a lattice by 8 of this unit cell (put them together)? For example, 4 unit cells on the top and 4 unit cells on the bottom of the lattice.

Here there is a trick for simple cubic but it does not work for may lattice!

$\endgroup$
7
$\begingroup$
ClearAll[latticeGrid]
latticeGrid[{lattice_String, {x_, y_, z_}}, opts : OptionsPattern[]] := 
 Module[{ld = LatticeData[lattice, "Image"], lengths, 
      tuples = Tuples[Range[0, # - 1] & /@ {x, y, z}]}, 
  lengths = -Subtract @@@ CoordinateBounds @ 
      DiscretizeGraphics[ld /. ( Sphere[__]:> {})];
  Show[ld /. prim : (_Polygon | _Line | _Sphere) :> 
      Translate[prim, lengths # & /@ tuples], opts]]

Examples:

latticeGrid[{"CenteredTetragonal", {4, 1, 2}}, ViewPoint -> {1, -3, 1}]

![enter image description here

latticeGrid[{"CenteredTetragonal", {2, 2, 3}}, ViewPoint -> {1, -3, 1}]

enter image description here

latticeGrid[{"FaceCenteredCubic", {3, 1, 3}}, ViewPoint -> {1, -3, 1}]

enter image description here

latticeGrid[{"TetrahedralPacking", {3, 1, 2}}, ViewPoint -> {1, -3, 1}]

enter image description here

$\endgroup$
3
  • $\begingroup$ Glorious!!! Wonderful!!! $\endgroup$ – Inzo Babaria Nov 1 '20 at 9:03
  • $\begingroup$ Is there any possibility to change the color of unit cells? Or it is by default and cannot be changed! $\endgroup$ – Inzo Babaria Nov 1 '20 at 9:07
  • $\begingroup$ @InzoBabaria, you can post-process to inject the desired styles. For example, latticeGrid[{"FaceCenteredCubic", {3, 1, 1}}, ViewPoint -> {1, -3, 1}] /. {p_Polygon :> {FaceForm[Blue], EdgeForm[Cyan], p}, l__Line :> {Red, l}, s__Sphere :> {Green, s}}. $\endgroup$ – kglr Nov 1 '20 at 9:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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