What is the best way in TikZ to draw a hexagonal stucture in 3D? For example, graphite crystals, honeycombs or stable racks made of hexagonal aligned stiffeners.
I already found this nice solution: Drawing hexagons. But this is only for 2D hexagons.
Currently I'm just writing down all nodes separately with (x,y,z) coordinates. But this has the disadvantages of being (a) very annoying, (b) connecting lines don't care about the layers (lines don't go "behind" plane 2 if I connect plane 1 and 3, it's just drawn on top).
What is the best way of realizing a 3D hexagonal structure in TikZ that takes care of the layers and don't needs all coordinates entered by hand but by an algorithm?
Best Answer
Here's another option, using this time
regular polygon
from theshapes
library; each of the the\hexgrid...
commands has two mandatory arguments: the first one, gives a name to the grid and the second one, controls the vertical shifting; the optional argument allows to pass additional options:The code admits still improvements, but the main point is that it can be used as a starting point to easily define hexagonal grids. The
siunitx
package was used to typeset the units (thanks to Svend Tveskæg for the reminder).