Function Repository Resource:

GeneralizedTriangularGridGraph

Source Notebook

Create a triangular grid graph with customizable width and height, represented as a parallelogram composed of triangular grids

Contributed by: Peter Cullen Burbery

ResourceFunction["GeneralizedTriangularGridGraph"][{width, height}]

generates a triangular grid graph with the specified width and height.

Details

The width and height should be positive integers.
ResourceFunction["GeneralizedTriangularGridGraph"] supports all Graph options.

Examples

Basic Examples (3) 

Form a triangular grid graph four elements wide and three tall:

In[1]:=
ResourceFunction["GeneralizedTriangularGridGraph"][{4, 3}]
Out[1]=

This graph is three elements wide and four tall:

In[2]:=
ResourceFunction["GeneralizedTriangularGridGraph"][{3, 4}, ImageSize -> Medium]
Out[2]=

Specify VertexLabels:

In[3]:=
ResourceFunction["GeneralizedTriangularGridGraph"][{3, 4}, VertexLabels -> Placed["Name", Tooltip]]
Out[3]=

Scope (4) 

Make a grid graph of 57 by 57:

In[4]:=
ResourceFunction["GeneralizedTriangularGridGraph"][{57, 57}]
Out[4]=

A graph of 58 by 58 will not plot:

In[5]:=
ResourceFunction["GeneralizedTriangularGridGraph"][{58, 58}]
Out[5]=

The output is nevertheless a graph:

In[6]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/956308a4-b328-4512-b006-537df3bab6e2"]
Out[6]=

Use GraphPlot to show it:

In[7]:=
(* Evaluate this cell to get the example input *) CloudGet["https://www.wolframcloud.com/obj/f503a537-a631-4443-b3d9-969788d89990"]
Out[7]=

Options (3) 

Color the background:

In[8]:=
ResourceFunction["GeneralizedTriangularGridGraph"][{21, 21}, Background -> LightBlue]
Out[8]=

Change the layout:

In[9]:=
ResourceFunction["GeneralizedTriangularGridGraph"][{21, 21}, GraphLayout -> "GridEmbedding"]
Out[9]=

Choose a vertex shape function:

Make the image large:

In[10]:=
ResourceFunction["GeneralizedTriangularGridGraph"][{21, 21}, ImageSize -> Large]
Out[10]=

VertexShapeFunction (2) 

Use built-in settings for VertexShapeFunction in the "Basic" collection:

In[11]:=
ResourceData["VertexShapeFunction", "Basic"]
Out[11]=

Simple basic shapes:

In[12]:=
Table[ResourceFunction["GeneralizedTriangularGridGraph"][{4, 4}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> vf, ImageSize -> 200], {vf, {"Triangle", "Square", "Rectangle", "Pentagon", "Hexagon", "Octagon"}}]
Out[12]=

Use built-in settings for VertexShapeFunction in the "Rounded" collection:

In[13]:=
ResourceData["VertexShapeFunction", "Rounded"]
Out[13]=
In[14]:=
Table[ResourceFunction["GeneralizedTriangularGridGraph"][{4, 4}, VertexShapeFunction -> vf, VertexSize -> 0.2, PlotLabel -> Style[vf, 9], ImageSize -> 200], {vf, ResourceData["VertexShapeFunction", "Rounded"]}]
Out[14]=

EdgeShapeFunction (3) 

Get a list of built-in settings for EdgeShapeFunction:

In[15]:=
ResourceData["EdgeShapeFunction"]
Out[15]=

Undirected edges including the basic line:

In[16]:=
ResourceFunction["GeneralizedTriangularGridGraph"][{4, 4}, EdgeShapeFunction -> "Line"]
Out[16]=

Lines with different glyphs on the edges:

In[17]:=
Table[Graph[
  DirectedGraph[
   ResourceFunction["GeneralizedTriangularGridGraph"][{4, 4}], "Random"], EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.05}}, PlotLabel -> ef, ImageSize -> Medium], {ef, {"BoxLine", "DiamondLine", "DotLine"}}]
Out[17]=

Directed edges including solid arrows:

In[18]:=
Table[Graph[
  DirectedGraph[
   ResourceFunction["GeneralizedTriangularGridGraph"][{4, 4}], "Random"], EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "FilledArrow"]}]
Out[18]=

Line arrows:

In[19]:=
Table[Graph[
  DirectedGraph[
   ResourceFunction["GeneralizedTriangularGridGraph"][{4, 4}], "Random"], EdgeShapeFunction -> {{ef, "ArrowSize" -> 0.1}}, PlotLabel -> ef], {ef, ResourceData["EdgeShapeFunction", "UnfilledArrow"]}]
Out[19]=

Properties and Relations (5) 

This is similar to GridGraph:

In[20]:=
GridGraph[{54, 54}]
Out[20]=

There's also the resource function HexagonalGridGraph which tiles the plane with hexagons:

In[21]:=
ResourceFunction["HexagonalGridGraph"][{21, 21}, ImageSize -> Medium]
Out[21]=

The function TriangularGridGraph does not support different height and width specifications:

In[22]:=
ResourceFunction["TriangularGridGraph"][21, ImageSize -> Medium]
Out[22]=

This function supports different height and width dimensions:

In[23]:=
ResourceFunction["GeneralizedTriangularGridGraph"][{21, 54}, ImageSize -> Medium]
Out[23]=

Make a short wide graph:

In[24]:=
ResourceFunction["GeneralizedTriangularGridGraph"][{54, 21}, ImageSize -> Medium]
Out[24]=

Publisher

Peter Burbery

Requirements

Wolfram Language 13.0 (December 2021) or above

Version History

  • 1.0.0 – 26 June 2023

Related Resources

License Information