# Function to define a supra-hexagonal grid

### Description

`sHexGrid`

is supposed to define a supra-hexagonal map grid. A
supra-hexagon is a giant hexagon, which seamlessly consists of smaller
hexagons. Due to the symmetric nature, it can be uniquely determined by
specifying the radius away from the grid centroid. This function takes
input the grid radius (or the number of hexagons in the grid, but will
be adjusted to meet the definition of supra-hexagon), and returns a
list (see 'Value' below) containing: the grid radius, the total number
of hexagons in the grid, the 2D coordinates of the grid centroid, the
step for each hexogan away from the grid centroid, and the 2D
coordinates of all hexagons in the grid.

### Usage

1 |

### Arguments

`r` |
an integer specifying the radius in a supra-hexagonal grid |

`nHex` |
the number of input hexagons in the grid |

### Value

a list with following components:

`r`

: the grid radius`nHex`

: the total number of hexagons in the grid. It may differ from the input value; actually it is always no less than the input one to ensure a supra-hexagonal grid exactly formed`centroid`

: the 2D coordinates of the grid centroid`stepCentroid`

: a vector with the length of nHex. It stores how many steps a hexagon is awawy from the grid centroid ('1' for the centroid itself). Starting with the centroid, it orders outward. Also, for those hexagons of the same step, it orders from the rightmost in an anti-clock wise`coord`

: a matrix of nHex x 2 with each row specifying the 2D coordinates of a hexagon in the grid. The order of rows is the same as 'centroid' above`call`

: the call that produced this result

### Note

The relationships among return values:

*nHex = 1+6*r*(r-1)/2**centroid = coord[1,]**stepCentroid[1] = 1**stepCentroid[2:nHex] = unlist(sapply(2:r, function(x) (c( (1+6*x*(x-1)/2-6*(x-1)+1) : (1+6*x*(x-1)/2) )>=1)*x ))*

### See Also

`sTopology`

### Examples

1 2 3 4 5 6 7 8 9 10 11 12 13 | ```
# The supra-hexagonal grid is exactly determined by specifying the radius.
res <- sHexGrid(r=2)
# The grid is determined according to the number of input hexagons (after being adjusted).
# The return res$nHex is always no less than the input one.
# It ensures a supra-hexagonal grid is exactly formed.
res <- sHexGrid(nHex=12)
# Ignore input nHex if r is also given
res <- sHexGrid(r=3, nHex=100)
# By default, r=3 if no parameters are specified
res <- sHexGrid()
``` |

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker. Vote for new features on Trello.