# SQUARE_HEX_GRID Routines for a Hexagonal Grid

SQUARE_HEX_GRID is a C++ library 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.
```

### Languages:

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

### Related Data and Programs:

BALL_GRID, a C++ library which computes a grid of points over the interior of a ball in 3D.

CIRCLE_ARC_GRID, a C++ program which computes points equally spaced along a circular arc;

CUBE_GRID, a C++ library which computes a grid of points over the interior of a cube in 3D.

DISK_GRID, a C++ library which computes a grid of points over the interior of a disk in 2D.

ELLIPSE_GRID, a C++ library which computes a grid of points over the interior of an ellipse in 2D.

ELLIPSOID_GRID, a C++ library which computes a grid of points over the interior of an ellipsoid in 3D.

HYPERCUBE_GRID, a C++ library which computes a grid of points over the interior of a hypercube in M dimensions.

LINE_GRID, a C++ library which computes a grid of points over the interior of a line segment in 1D.

POLYGON_GRID, a C++ library which generates a grid of points over the interior of a polygon in 2D.

PYRAMID_GRID, a C++ library which computes a grid of points over the interior of the unit pyramid in 3D;

SIMPLEX_GRID, a C++ library which generates a regular grid of points over the interior of an arbitrary simplex in M dimensions.

SPHERE_FIBONACCI_GRID, a C++ library which uses a Fibonacci spiral to create a grid of points on the surface of the unit sphere in 3D.

SPHERE_GRID, a C++ library which provides a number of ways of generating grids of points, or of points and lines, or of points and lines and faces, on the surface of the unit sphere in 3D.

SPHERE_LLQ_GRID, a C++ library which uses longitudes and latitudes to create grids of points, lines, and quadrilaterals on the surface of the unit sphere in 3D.

SPHERE_LLT_GRID, a C++ library which uses longitudes and latitudes to create grids of points, lines, and triangles on the surface of the unit sphere in 3D.

SQUARE_GRID, a C++ library which computes a grid of points over the interior of a square in 2D.

TETRAHEDRON_GRID, a C++ library which computes a grid of points over the interior of a tetrahedron in 3D.

TRIANGLE_GRID, a C++ library which computes a grid of points over the interior of a triangle in 2D.

WEDGE_GRID, a C++ library which computes a grid of points over the interior of the unit wedge in 3D.

### Examples and Tests:

Note that many text and graphics files are created by the calling program, but these are stored in the SQUARE_HEX_GRID datasets directory.

### List of Routines:

• BOX_PRINT_2D prints information about a coordinate box in 2D.
• HEX_GRID_01_APPROXIMATE_H seeks a unit square hex grid with spacing H.
• HEX_GRID_01_APPROXIMATE_N seeks a unit square hex grid of about N nodes.
• HEX_GRID_01_H computes the unit square hex grid spacings.
• HEX_GRID_01_LAYERS computes the unit square hex grid column width.
• HEX_GRID_01_N computes the number of unit square hex grid points.
• HEX_GRID_01_POINTS returns unit square hex grid points.
• HEX_GRID_APPROXIMATE_H seeks a hex grid with spacing H.
• HEX_GRID_APPROXIMATE_N seeks a hex grid of about N nodes.
• HEX_GRID_H computes the coordinate box hex grid spacings.
• HEX_GRID_LAYERS computes the coordinate box hex grid column width.
• HEX_GRID_N computes the number of coordinate box hex grid points.
• HEX_GRID_PLOT creates GNUPLOT graphics files of a hex grid.
• HEX_GRID_POINTS returns coordinate box hex grid points.
• HEX_GRID_WRITE writes a hex grid dataset to a file.
• S_BLANK_DELETE removes blanks from a string, left justifying the remainder.
• TIMESTAMP prints the current YMDHMS date as a time stamp.

You can go up one level to the C++ source codes.

Last revised on 30 August 2014.