triangular_lattice_graph(m, n, periodic=False, with_positions=True, create_using=None)¶
Returns the \(m\) by \(n\) triangular lattice graph.
The returned graph has \(m\) rows and \(n\) columns of triangles. Rows and columns include both triangles pointing up and down. Rows form a strip of constant height. Columns form a series of diamond shapes, staggered with the columns on either side. Another way to state the size is that the nodes form a grid of
(n + 1) // 2columns. The odd row nodes are shifted horizontally relative to the even rows.
Directed graph types have edges pointed up or right.
Positions of nodes are computed by default or
with_positions is True. The position of each node (embedded in a euclidean plane) is stored in the graph using equilateral triangles with sidelength 1. The height between rows of nodes is thus \(\sqrt(3)/2\). Nodes lie in the first quadrant with the node \((0, 0)\) at the origin.
- m (int) – The number of rows in the lattice.
- n (int) – The number of columns in the lattice.
- periodic (bool (default: False)) – If True, join the boundary vertices of the grid using periodic
boundary conditions. The join between boundaries is the final row
and column of triangles. This means there is one row and one column
fewer nodes for the periodic lattice. Periodic lattices require
m >= 3,
n >= 5and are allowed but misaligned if
- with_positions (bool (default: True)) – Store the coordinates of each node in the graph node attribute ‘pos’. The coordinates provide a lattice with equilateral triangles. Periodic positions shift the nodes vertically in a nonlinear way so the edges don’t overlap so much.
- create_using (NetworkX graph constructor, optional (default=nx.Graph)) – Graph type to create. If graph instance, then cleared before populated.
The m by n triangular lattice graph.