The Perl and Raku Conference 2025: Greenville, South Carolina - June 27-29 Learn more

NAME

Graph::Maker::HexGrid - create hexagonal grid graphs

SYNOPSIS

$graph = Graph::Maker->new ('hex_grid');

DESCRIPTION

Graph::Maker::HexGrid creates a Graph.pm graph of hexagons arranged in a hexagonal shape,

*---*
/ \
*---* *---*
/ \ / \ dims => [4,3,2]
*---* *---* *---*
/ \ / \ / \
* *---* *---* *---*
\ / \ / \ / \
*---* *---* *---* *
/ \ / \ / \ /
* *---* *---* *---*
\ / \ / \ / \
*---* *---* *---* *
\ / \ / \ /
*---* *---* *---*
\ / \ /
*---* *---*
\ /
*---*

dims is the side lengths of the hexagonal shape. The example above is 4 hexagons along the bottom left side, then 3 for the bottom right, and 2 vertically. The opposite sides the same 4,3,2.

If a side is 1 then the result is a parallelogram of hexagons.

*---*
/ \
*---* *---*
/ \ / \ dims => [4,3,1]
*---* *---* *---*
/ \ / \ / \
* *---* *---* *---*
\ / \ / \ / \
*---* *---* *---* *
\ / \ / \ /
*---* *---* *---*
\ / \ /
*---* *---*
\ /
*---*

If two sides are 1 then the result is line of hexagons, like a ladder (Graph::Maker::Ladder) with every second rung.

*---*
/ \ dims => [3,1,1]
* *---*
\ / \
*---* *---*
\ / \
*---* *
\ /
*---*

The order in which dims are given doesn't matter. Any cyclic rotation is just the graph rotated, and reversing is a mirror image, so any order is an isomorphic graph.

Vertex names are currently x,y coordinates used in the construction, but don't rely on that.

FUNCTIONS

$graph = Graph::Maker->new('hex_grid', key => value, ...)

The key/value parameters are

dims => arrayref of 3 integers
graph_maker => subr(key=>value) constructor, default Graph->new

Other parameters are passed to the constructor, either graph_maker or Graph->new().

If the graph is directed (the default) then edges are added both ways between vertices (like Graph::Maker::Grid does). Option undirected => 1 creates an undirected graph and for it there is a single edge between vertices.

HOUSE OF GRAPHS

House of Graphs entries for graphs here include

670 1,1,1 6-cycle
28529 2,2,2
28500 3,3,3

OEIS

Entries in Sloane's Online Encyclopedia of Integer Sequences related to this tree include

A143366 Wiener index of NxNxN

SEE ALSO

Graph::Maker, Graph::Maker::Cycle, Graph::Maker::Grid

HOME PAGE

http://user42.tuxfamily.org/graph-maker-other/index.html

LICENSE

Copyright 2017, 2018, 2019, 2020, 2021 Kevin Ryde

This file is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

This file is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with This file. If not, see http://www.gnu.org/licenses/.