square_hex_grid


square_hex_grid, a MATLAB code which computes a hexagonally staggered grid of points over the interior of a square in 2D.

For one set of routines, the hexagonal grid is defined in the unit square [0,1] x [0,1]. For a matching set of routines, the hexagonal grid is defined on a coordinate box [A,B] x [C,D].

All nodes of the grid lie on one of LAYERS horizontal lines. The first of these lines is the X axis (for grids in the unit square) or the line from (A,C) to (B,C), for grids in a coordinate box. Each successive line is HY units higher.

On all the odd numbered lines, there are NODES_PER_LAYER points, equally spaced from 0 to 1 or A to B, with a spacing of HX.

On the even numbered lines, there are NODES_PER_LAYER-1 points, whose values are the midpoints of successive intervals on an odd numbered line. (The grid is staggered).

In order to maintain the hexagonal structure, the following relationship is required between HX and HY:

        HY = HX * sqrt ( 3 ) / 2.
      

Here is an image of a hexagonal grid with NODES_PER_ROW = 21 and LAYERS = 24, and a total of N = 492 nodes.

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Languages:

SQUARE_HEX_GRID is available in a C++ version and a FORTRAN90 version and a MATLAB version.

Related Data and Programs:

matlab_grid, a MATLAB code which generates a regular grid of points inside a variety of regions in one, two, three or many dimensions.

Source Code:


Last revised on 06 December 2022.