Hexagonally Staggered Grid Points in a Square

**SQUARE_HEX_GRID**
is a MATLAB library 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.

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

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

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

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

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

CVT, a MATLAB library which computes elements of a Centroidal Voronoi Tessellation.

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

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

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

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

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

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

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

SIMPLEX_GRID, a MATLAB library which generates a grid of points over the interior of a simplex in M dimensions.

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

SPHERE_GRID, a MATLAB 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 MATLAB library which uses longitudes and latitudes to create grids of points, lines, and quadrilaterals on the surface of the unit sphere in 3D.

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

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

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

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

- box_print_2d.m, prints information about a coordinate box in 2D.
- hex_grid_01_approximate_h.m, seeks a unit square hex grid with spacing H.
- hex_grid_01_approximate_n.m, seeks a unit square hex grid of about N nodes.
- hex_grid_01_h.m, computes the unit square hex grid spacings.
- hex_grid_01_layers.m, computes the unit square hex grid column width.
- hex_grid_01_n.m, computes the number of unit square hex grid points.
- hex_grid_01_points.m, returns unit square hex grid points.
- hex_grid_approximate_h.m, seeks a hex grid with spacing H.
- hex_grid_approximate_n.m, seeks a hex grid of about N nodes.
- hex_grid_h.m, computes the coordinate box hex grid spacings.
- hex_grid_layers.m, computes the coordinate box hex grid column width.
- hex_grid_n.m, computes the number of coordinate box hex grid points.
- hex_grid_points.m, returns coordinate box hex grid points.
- hex_grid_write.m, writes a hex grid dataset to a file.
- s_blank_delete.m, removes blanks from a string, left justifying the remainder.
- timestamp.m, prints the current YMDHMS date as a time stamp.

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

- square_hex_grid_test.m, a sample calling program.
- square_hex_grid_test_output.txt, the output file.
- square_hex_grid_test01.m, tests HEX_GRID_01_LAYERS.
- square_hex_grid_test02.m, tests HEX_GRID_01_H.
- square_hex_grid_test03.m, tests HEX_GRID_01_N.
- square_hex_grid_test04.m, tests HEX_GRID_01_POINTS.
- square_hex_grid_test05.m, tests HEX_GRID_01_APPROXIMATE_N.
- square_hex_grid_test06.m, tests HEX_GRID_01_APPROXIMATE_H.
- square_hex_grid_test07.m, tests HEX_GRID_LAYERS.
- square_hex_grid_test08.m, tests HEX_GRID_H.
- square_hex_grid_test09.m, tests HEX_GRID_N.
- square_hex_grid_test10.m, tests HEX_GRID_POINTS.
- square_hex_grid_test11.m, tests HEX_GRID_APPROXIMATE_N.
- square_hex_grid_test12.m, tests HEX_GRID_APPROXIMATE_H.

You can go up one level to the MATLAB source codes.