square_hex_grid


square_hex_grid, a C++ code which computes a hexagonal 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.
      

Licensing:

The information on this web page is distributed under the MIT license.

Languages:

square_hex_grid is available in a C++ version and a Fortran90 version and a MATLAB version and an Octave version.

Related Data and Programs:

square_hex_grid_test

cpp_grid, a C++ 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.