Function Resource

Function Repository Resource:

TriangularLatticeGraph

Source Notebook

Generate a graph corresponding to a triangular grid

Contributed by: Anton Antonov

ResourceFunction["TriangularLatticeGraph"][n]

returns a triangular lattice graph with dimensions n×n.

ResourceFunction["TriangularLatticeGraph"][{rows,columns}]

returns a triangular lattice graph with dimensions rows×columns.

Details and Options

ResourceFunction["TriangularLatticeGraph"] takes the same options as Graph.

Examples

Basic Examples (1) 

A 4×7 hexagonal grid graph:

In[1]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/TriangularLatticeGraph"]][{4, 7}]
Out[1]=

Scope (3) 

Using only one argument:

In[2]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/TriangularLatticeGraph"]][4]
Out[2]=

Use a different graph embedding:

In[3]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/TriangularLatticeGraph"]][{12, 8}, GraphLayout -> "SpringElectricalEmbedding", VertexCoordinates -> Automatic]
Out[3]=

Use a different plot theme:

In[4]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/TriangularLatticeGraph"]][{18, 18}, PlotTheme -> "LargeGraph"]
Out[4]=

Applications (1) 

Make a (full) triangular grid graph with vertices that are the centers of a hexagonal graph:

In[5]:=
g1 = ResourceFunction["HexagonalGridGraph"][{7, 4}];
g2 = ResourceFunction[
CloudObject[
    "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/TriangularLatticeGraph"]][{3, 6}];
g2 = Graph[g2, VertexCoordinates -> Thread[VertexList[g2] -> Map[# + {Sqrt[3], 1} &, GraphEmbedding[g2]]]];
Show[g1, HighlightGraph[g2, g2]]
Out[6]=

Properties and Relations (4) 

The resource function "HexagonalGridGraph" takes width and height as argument, while TriangularLatticeGraph takes rows and columns. The latter is more consistent with GridGraph. Here is a comparison:

In[7]:=
Row[{ResourceFunction["HexagonalGridGraph"][{3, 6}], ResourceFunction[
CloudObject[
    "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/TriangularLatticeGraph"]][{3, 6}], GridGraph[{3, 6}]}]
Out[7]=

The resource function "TriangulaGridGraph" takes only one argument for the graph size and makes triangle shaped graphs. Here is a comparison:

In[8]:=
Row[{ResourceFunction["TriangularGridGraph"][4], ResourceFunction[
CloudObject[
    "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/TriangularLatticeGraph"]][{5, 4}]}]
Out[8]=

The mesh points of the Voronoi tessellation of the points of a triangular lattice graph contain the points of a hexagonal grid graph. Here is a demonstration:

In[9]:=
n = 10;
points = GraphEmbedding@ResourceFunction[
CloudObject[
     "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/TriangularLatticeGraph"]][n];
\[ScriptCapitalR] = VoronoiMesh[points];
lines = MeshPrimitives[\[ScriptCapitalR], "Lines"];
Legended[
 Graphics[{GrayLevel[0.7], lines, Red, Point@Map[# + 2*{Sqrt[3], 1} &, GraphEmbedding@
      ResourceFunction["HexagonalGridGraph"][{n - 1, n - 1}]], Black, Point[points]}, ImageSize -> Large],
 SwatchLegend[{GrayLevel[0.7], Red, Black}, {"Voronoi mesh", "Hexagonal grid graph embedding", "Triangular lattice graph embedding"}]]
Out[13]=

The opposite is also true:

In[14]:=
VoronoiMesh[
 GraphEmbedding@ResourceFunction["HexagonalGridGraph"][{10, 10}]]
Out[14]=

Large graphs may be formatted differently in OutputForm than smaller graphs. A 50×60 hexagonal grid graph shows explicit edges and vertices:

In[15]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/TriangularLatticeGraph"]][{50, 60}]
Out[15]=

A 60×60 hexagonal grid graph displays as an elided Graph expression:

In[16]:=
ResourceFunction[
CloudObject[
  "https://www.wolframcloud.com/obj/antononcube/DeployedResources/Function/TriangularLatticeGraph"]][{60, 60}]
Out[16]=