Skip to content
conklech edited this page Nov 15, 2013 · 56 revisions

Overview of Grid

Grid provides tools for working with regular arrangements of tiles, such as might be used in a board game or self-organising map (SOM). Grid currently supports triangular, square, hexagonal, and octagonal tiles, with various 2D and toroidal layouts.

Choosing the appropriate grid

In this package, tiles are called "triangular", "square", etc., based on the number of neighbours they have. For example, a square tile has four neighbours, and a hexagonal tile has six. There are only three regular polygons that can tile a plane: triangles, squares, and hexagons. Of course, other plane tilings are possible if you use irregular polygons, or curved shapes, or if you combine tiles of different shapes.

When you tile other surfaces, things get very interesting. For example, octagons will tile a hyperbolic plane. (Alternatively, you can think of these as squares on a board game where diagonal moves are allowed.)

For a board game, you probably want to choose the grid type based on the number of directions a player can move, rather than the number of sides the tile will have when you display it. For example, in a game that uses square tiles and allows the user to move diagonally as well as horizontally and vertically, consider using one of the grids with octagonal tiles to model the board. You can still display the tiles as squares, but for internal calculations they are octagons.

How to use Grid

See the example in the haddock documentation for Math.Geometry.Grid.

If you're curious about the equations used, see Implementation: Triangular tiles or Implementation: Hexagonal tiles.

Grid layouts