getNumCells method

int getNumCells(
  1. int res,
  2. Pointer<Int64> out
)

@defgroup getNumCells getNumCells Functions for getNumCells @{ / /** @brief number of cells (hexagons and pentagons) for a given resolution

It works out to be 2 + 120*7^r for resolution r.

Mathematical notes

Let h(n) be the number of children n levels below a single hexagon.

Then h(n) = 7^n.

Let p(n) be the number of children n levels below a single pentagon.

Then p(0) = 1, and p(1) = 6, since each pentagon has 5 hexagonal immediate children and 1 pentagonal immediate child.

In general, we have the recurrence relation

p(n) = 5h(n-1) + p(n-1) = 57^(n-1) + p(n-1).

Working through the recurrence, we get that

p(n) = 1 + 5*\sum_{k=1}^n 7^{k-1} = 1 + 5*(7^n - 1)/6,

using the closed form for a geometric series.

Using the closed forms for h(n) and p(n), we can get a closed form for the total number of cells at resolution r:

c(r) = 12p(r) + 110h(r) = 2 + 120*7^r.

@param res H3 cell resolution

@return number of cells at resolution res

Implementation

int getNumCells(
  int res,
  ffi.Pointer<ffi.Int64> out,
) {
  return _getNumCells(
    res,
    out,
  );
}