TriangularLatticeGraph

Generate a graph corresponding to a triangular grid

DefinitionResourceCreateNotebook

Clear[TriangularLatticeGraph];
TriangularLatticeGraph[rows_Integer?Positive,opts:OptionsPattern[Graph]]:=TriangularLatticeGraph[{rows,rows},opts];
TriangularLatticeGraph[{rows_Integer?Positive,columns_Integer?Positive},opts:OptionsPattern[Graph]]:=
 Module[{cells,edges, vertices,top,right,endVertex}, 
cells=Table[CirclePoints[{(Sqrt[3])(2j+k-2 ),3k-2},{2,π/2},3],{k,rows},{j,columns}];
right=First/@Map[Function[{row},Select[Flatten[row,1],#[[1]]==Max[Flatten[row,1][[All,1]]]&]],cells];
cells=Flatten[cells,1];
edges=Union[Sort/@Flatten[Partition[#,2,1,1]&/@cells,1]];
vertices=Union[Flatten[edges,1]];
top=Partition[Sort[Select[vertices,#[[2]]==Max[vertices[[All,2]]]&]],2,1];
endVertex={2*top[[-1,-1,1]]-top[[-1,-2,1]],top[[-1,-1,2]]};
AppendTo[vertices,endVertex];
edges=Join[edges,top];
right=Partition[Sort[right],2,1];
edges=Join[edges,right];
edges=Join[edges,Join[{{endVertex,top[[-1,-1]]},{endVertex,right[[-1,-1]]}}]];
IndexGraph[Graph[vertices,UndirectedEdge@@@edges,opts, VertexCoordinates->Thread[vertices-> vertices]]]
];

Documentation

UsageResourceCreateNotebook

Details & OptionsResourceCreateNotebook

TriangularLatticeGraph takes the same options as Graph.

ExamplesResourceCreateNotebook

Basic Examples

A 4×7 hexagonal grid graph:

TriangularLatticeGraph[{4,7}]

Scope

Using only one argument:

TriangularLatticeGraph[4]

Use a different graph embedding:

TriangularLatticeGraph[{12,8},GraphLayout->"SpringElectricalEmbedding",VertexCoordinates->Automatic]

Use a different plot theme:

TriangularLatticeGraph[{18,18},PlotTheme->"LargeGraph"]

Applications

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

g1=ResourceFunction["HexagonalGridGraph"][{7,4}];
g2=TriangularLatticeGraph[{3,6}];
g2=Graph[g2,VertexCoordinates->Thread[VertexList[g2]->Map[#+{(Sqrt[3]),1}&,GraphEmbedding[g2]]]];
Show[g1,HighlightGraph[g2,g2]]

Properties and Relations

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:

Row[{ResourceFunction["HexagonalGridGraph"][{3,6}],TriangularLatticeGraph[{3,6}],GridGraph[{3,6}]}]

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

Row[{ResourceFunction["TriangularGridGraph"][4],TriangularLatticeGraph[{5,4}]}]

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:

n=10;
points=GraphEmbedding@TriangularLatticeGraph[n];
ℛ=VoronoiMesh[points];
lines=MeshPrimitives[ℛ,"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"}]]

The opposite is also true:

VoronoiMesh[GraphEmbedding@ResourceFunction["HexagonalGridGraph"][{10,10}]]

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

TriangularLatticeGraph[{50,60}]

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

TriangularLatticeGraph[{60,60}]

Source & Additional Information

Contributed ByResourceCreateNotebook

Anton Antonov

KeywordsResourceCreateNotebook

beehive

honeycomb

triangles

lattice

hexagons

CategoriesResourceCreateNotebook

Related SymbolsResourceCreateNotebook

Graph

GridGraph

AdjacencyGraph

GraphEmbedding

VoronoiMesh

Related Resource ObjectsResourceCreateNotebook

HexagonalGridGraph

TriangularGridGraph

Source/Reference CitationResourceCreateNotebook

Source, reference or citation information

LinksResourceCreateNotebook

Link to other related material

TestsResourceCreateNotebook

TriangularLatticeGraph[4]

TriangularLatticeGraph[{5,9}]

CompatibilityResourceCreateNotebook

Wolfram Language VersionResourceCreateNotebook

12.3+

Operating SystemResourceCreateNotebook

EnvironmentsResourceCreateNotebook

Cloud SupportResourceCreateNotebook

Required FeaturesResourceCreateNotebook

Author NotesResourceCreateNotebook

Additional information about limitations, issues, etc.

Submission NotesResourceCreateNotebook

Additional information for the reviewer.