Skip to contents

Consider a map with boundaries (x1,y1,x2,y2)(x_1, y_1, x_2, y_2) such that

  • x1x_1 and x2x_2 denote the minimum and maximum longitude of the map, respectively,
  • y1y_1 and y2y_2 denote the minimum and maximum latitude of the map, respectively,
  • A=(y2y1)(x2x1)A = (y_2 - y_1)(x_2 - x_1) is the total area of the map,
  • LL is the total land area of the map,
  • nxen_{xe} and nxon_{xo} is the total number of hexagons on even and odd rows respectively,
  • nyen_{ye} and nyon_{yo} is the total number of hexagons on even and odd columns respectively,
  • nrn_r and ncn_c are the maximum number of rows and columns in the grid structure,
  • nn is the desired total number of hexagons,
  • cc is the cell size, which is the same as the width of the non-flat topped hexagon.

We assume that the hexagon is not flat topped. Note that AA, LL, nn, x1x_1, x2x_2, y1y_1 and y2y_2 are known.

Below is an example where the “map” is a unit square. In this case A=LA = L.

square <- matrix(c(0, 0, 
                   0, 1, 
                   1, 1, 
                   1, 0, 
                   0, 0), 
                 ncol = 2, 
                 byrow = TRUE) %>% 
  list() %>% 
  st_polygon()

plot_hex_tile <- function(cellsize = NULL, n = NULL) {
  title <- ifelse(is.null(cellsize),
                  paste0("n = ", n),
                  paste0("Cell size = ", cellsize))
  if(is.null(cellsize)) {
    title <- paste0("n = ", n)
    grid <- st_make_grid(square, n = n, square = FALSE)
  } else {
    title <- paste0("Cell size = ", cellsize)
    grid <- st_make_grid(square, 
                         cellsize = cellsize,
                         square = FALSE)
  }
  
  ggplot(grid) +
    geom_sf(fill = "transparent") + 
    geom_sf(data = square, fill = "transparent", color = "red") +
    ggtitle(title)
}

plot_hex_tile(0.25)

plot_hex_tile(0.3)

plot_hex_tile(0.5)

plot_hex_tile(1)

plot_hex_tile(n = 3)

plot_hex_tile(n = 5)

Using basic trigonometry for a regular hexagon of height hh, width ww and length bb as shown in the diagram below, you can find that h=2w/3h = 2 w / \sqrt{3} and b=w/3b = w / \sqrt{3} .

Putting it all together, you can find that the maximum and minimum number of hexagons in a row is x2x1/c+2\lfloor x_2 - x_1 \rfloor / c + 2 (even rows) and x2x1/c+1\lfloor x_2 - x_1 \rfloor / c + 1 (odd rows), respectively. The maximum and minimum number of hexagons in a column (which we define as the number of hexagon where its center passes through a vertical line) is (y2y1+h/2b)/(h+b)+1\lfloor (y_2 - y_1 + h / 2 - b) / (h + b) \rfloor + 1 and (y2y1+h/2b)/(h+b)\lfloor (y_2 - y_1 + h / 2 - b) / (h + b) \rfloor (need to double check this).