1. Introduction
A spacefilling curve (SFC) represents a bijective transformation of multidimensional points onto 1D representation by computing an index (hash code) for each point defining the linear order of points in the space [
1]. A SFC hashing algorithm usually follows a pattern of some tree or pyramid structure. SFCs are utilized, e.g., for space indexing and range querying [
1,
2,
3] and also for building spatial hierarchies especially for parallel platforms [
4,
5]. While the SFCs based on orthogonal and triangular uniform grids are well investigated and preferred in the applications, we propose an effective and robust hexagonal NodeGosper SFC based on the Gosper fractal [
6] (
Figure 1). This paper analyzes the problems of hierarchical hexagonal indexing and proposes solutions of issues related to transformations of multiresolution hexagonal grids and fractal shape of Gosper tiles. Our novel method overcomes the lacks of naive Gosperbased approaches [
7,
8] and competes well with other nonhexagonal SFCs.
A point cloud (PC) is a collection of points of the same type (23D real points) [
9] representing a discrete form of real objects. Beside traditional PCs produced mostly by 3D scanners [
9], a set of points can also represent general spatial information [
10] such as location, GPS coordinates on the map [
11], swarm particles [
12], nodes of graph generated by visualization algorithms [
13], etc. We focus on 2D point clouds as they are highly investigated in the areas such as data mining [
2,
3,
10], computer graphics [
14,
15], image analysis [
16,
17,
18], geographic information systems (GISs) [
19,
20,
21,
22,
23], sensor networks [
24,
25], triangulation [
26,
27,
28,
29] and data visualization [
12]. In the mentioned application fields, the point indexing/clustering algorithms are crucial, e.g., for efficient organization of data in the memory, analyzing their properties, visualization of clusters, computation of forces in particle systems and searching near neighbors. Point indexing algorithms decompose the space into subspaces or tiles [
1,
10] containing a subset and create structures for effective addressing of the points. Usually, the structures utilize the uniform regular grids that are represented by list of clusters [
30], or the clusters are organized in the hierarchical manner to reduce the costs of point queries [
2,
10] by omitting irrelevant clusters such as empty or distant ones (
Figure 1a). The hierarchies offer good query times, esp. for sparse datasets, but they are often memory consuming and unbalanced [
5,
31]. Linear methods save memory usage and provide constant query time for uniformly distributed datasets [
30]. However, they are inefficient for sparse point clouds.
The spacefilling curves combine both approaches as they define the linear order of clusters and preserve the hierarchical information about points in the hash codes. To compute an index uniquely addressing a point in a hierarchy covering the whole space, the multiresolution grids are often used. Most widely used SFCs including Peano, Zorder, Hilbert and Sierpiński SFC [
1,
32,
33,
34] are for orthogonal or triangular grids. The multiresolution hexagonal grids were utilized for image processing [
18,
35,
36,
37]. Burt [
38] proposed a structure for coding binary images with hexagonal grids and Gibson and Lucas [
39] extended this structure to the more sophisticated Generalized Balanced Ternary (GBT). Those methods serve to decompose and represent images with pixels having positive coordinates, but they do not offer any general method for real points indexing and querying. Several papers discussed the problems of different grid systems and their mutual conversion to combine their best properties [
21,
22,
23], but they all miss the correct hierarchical 1to7 refinement in the hexagonal grid (
Figure 2) for a correct hexagonal SFC. During the last years, the hexagons have gained increased interest in scientific areas including geographic information systems [
19,
20,
21,
22,
23,
40,
41], data clustering and querying [
36,
38,
39,
42,
43], data visualization [
44,
45], computer graphics [
46] and computer or sensor networks [
24,
25]. Recently, the transportation network company Uber Technologies Inc. introduced a discrete global grid system [
11] based on multiresolution hexagonal grids. They use it to localize cars and customers on the map, to efficiently optimize ride pricing and dispatch and to visualize and explore spatial data. The GPS coordinates of locations on the map represent the points that are indexed by hexagonal grids. The hexagons also form the basis for analysis of the Uber marketplace, they can easily approximate zones defined by edges of required area on the map and they minimize the quantization error [
11]. Unlike squares and triangles, hexagons have uniform distance between neighboring cells and they have the optimal perimeter/area ratio which leads to good approximation of circles [
47].
While the hexagonal grids have a wide range of applications and a convenient linear representation could simplify performing point indexing, the hexagonal SFCs are not utilized very often. The main obstacle is that a hexagon is not a reptile. A reptile is a tile which is infinitely decomposable into similar tiles. A hexagon can be decomposed only into triangles, thus the hierarchy has to be defined by bottomup composition of hexagons creating a system of multiresolution grids [
10]. After exploring different hexagonal patterns, we decided to follow the concept of the Gosper fractal (or Flowsnake) which is a selfsimilar recursive fractal discovered by William Gosper in 1973 and introduced by Martin Gardner in 1976 [
6,
48] (
Figure 2). The fractal connects the vertices of hexagonal lattice and creates a pattern of 7 hexagons called the Gosper island. These islands can be composed again into 7pattern to create an island of greater level (
Figure 2). We define a procedure extending the Gosper fractal to its node form (NodeGosper curve) for point indexing in the manner of SFCs. The key tasks are: point localization in the hierarchy and inverse point mapping algorithm. The first published method [
7] simply decomposes the points into 7 disjoint areas in the topdown manner to approximate the hexagonal 7pattern. The paper [
7] shows that the topdown decomposition is not reliable and it cannot produce a correct hexagonal hierarchy. The Gosper islands are nonconvex fractal tiles (
Figure 2) with jagged edges that are fitted into surrounding ones. This leads to point mislocalization in the hierarchy (esp. at the edges) which produces many nonhexagonal clusters in the lower levels of decomposition. Thus, the hexagonal properties are not preserved. Later, the inverse bottomup mapping procedure fixing those problems was theoretically proposed [
8], but its mapping algorithm is inaccurate and inefficient. To the best of our knowledge, there is no straightforward hashing algorithm mapping the points onto the Gosper curve.
This paper summarizes a background about hexagonal grids and Gosper fractal to understand the advantages and lacks of hexagons and hexagonal multiresolution grids. The main contribution of this work lies in the derivation of the hexagonal spacefilling curve solving the lacks by using the pattern of the Gosper fractal to make a hexagonal linearization available to wide range of applications. We focus on correct point localization in the Gosper islands, stable point mapping onto the Gosper curve, fast determination of related hexagonal pattern, its rotation and indexation and efficient design of these algorithms. Our Gosper SFC method is supported by several theoretical metrics, e.g., Honeycomb conjecture [
47] proving good coverage of a circle by hexagonal grid, distance metrics [
49] declaring good real distance between points neighboring along the curve and construction times comparison. The metrics are verified by practical experiments comparing different grids and SFCs which show that our NodeGosper SFC is robust and it produces the correct hexagonal hierarchy without mislocalization much faster than previous approaches [
7,
8].
The paper is organized as follows.
Section 2 describes the related theoretical background we need for hierarchical hexagonal clustering.
Section 3 gives the details of our hierarchical hexagonal composition and the corresponding NodeGosper SFC construction. Finally,
Section 4 evaluates our SFC by comparing against other grids and spacefilling curves.
3. NodeGosper SpaceFilling Curve
We mentioned the main issues related to hexagonal hierarchy such as impossibility of recursive decomposition and fractal shape of Gosper islands that make it difficult to design a correct point mapping algorithm. The solutions proposed by previous work are insufficient. The approximative topdown decomposition [
7] following the fractal drawing algorithm produces deformed polygons and obviously incorrect point localization. The naive bottomup approach [
8] solving the issue with point localization and producing the correct NodeGosper SFC proposes only a theoretical pipeline with bad accuracy and performance.
This section represents the main contribution of the paper addressing all the named issues related to hierarchical hexagonal point indexing. We improve the existing simple concepts from papers [
7,
8] and define the complete hexagonbased system in detail with mathematical definitions and pseudocodes.
At first, the mathematical definition and the recursive construction of the Gosper fractal is reminded in
Section 3.1. Following the transformations defined for the Gosper fractal, we introduce our NodeGosper indexation model in
Section 3.2 which gives the right order to the hashed points. Next, we define the procedure computing a hexagon centroid according to its hash code based on the indexation model and topdown drawing algorithm of the Gosper fractal.
Section 3.4 defines our novel mapping algorithm representing the hashing function which correctly maps a point onto the NodeGosper curve and returns the corresponding hash code.
3.1. Gosper Fractal
Our NodeGosper SFC is inspired by the Gosper fractal drawing algorithm which is reminded here. The Gosper fractal is based on the pattern of seven hexagons (
Figure 7a). The fractal is recursively constructed by replacing the oriented red arrows with the properly rotated and scaled pattern in the topdown manner (
Figure 7b). The arrows connect the vertices of the hexagonal grid, and thus, this iterative method secures the geometrical continuity of the patterns and draws the correct image of the fractal. Alternatively, the same procedure can be applied to the nodebased pattern (
Figure 7c) connecting the hexagon centers which was probably first mentioned by Ventrella [
56] and its design is better for point indexing than the vertex one. The derivation of exact mathematical properties of the Gosper fractal is crucial for the NodeGosper SFC definition and we briefly remind them here. See papers [
7,
8,
57,
58] for details.
Figure 8 describes the transformation of the pattern replacing the base hexagon inscribed in the unit circle of
$size=1$ (black dashes) by seven smaller hexagons (level1 Gosper island). A hexagon itself practically represents a level0 Gosper island. The figure also shows two features of the Gosper islands: The Gosper island preserves the area of the parent hexagon, but its perimeter limit is infinity. The scale factor
$r=\frac{1}{\sqrt{7}}$ can be computed according to the blue triangle (
Figure 8) using the Law of Cosine and it also represents the size of child hexagons. The angle
$\alpha =arcsin\left(\frac{\sqrt{3}}{2\sqrt{7}}\right)$ can be computed using the Law of Sine and the scale factor
r.
Figure 7a shows that the patterns replacing differently oriented arrows have to be additionally rotated. The angles of orientation are defined by function
$f\left(y\right)$ in (
1). Going through the basic Gosper pattern (
Figure 7a) from the first vertex
$(0,0)$ to the last vertex
$(1,0)$, the hexagons 0 and 3 are rotated by
${120}^{\circ}$ and the hexagon 5 by
${120}^{\circ}$. The transformations can be easily computed using the wellknown matrices for rotation (
2), scale and translation.
3.2. NodeGosper Indexation
While the recursive method described in the previous section serves only to draw an image of the Gosper fractal with geometrical continuity, the indexation model must precisely state the order of the clusters along the SFC. Each point $\overrightarrow{p}$ of the point cloud is localized in the hexagonal grid and the corresponding hexagon is assigned a bit hash code representing its serial number. This section explains our indexation model of the hexagons ordered by the NodeGosper SFC.
The basic patterns defining rotation and indexation are shown in
Figure 9. The main point is that the subordinate patterns have different order of indices depending on the indexation of the parent pattern. For the indexation model, the geometrical continuity is insufficient.
Thus, two structural patterns are described in
Figure 9b,c. They define both forward (F) and backward (B) indexing variants. The Fpattern is initial and the curve indexation is calculated in the topdown manner. Each hexagon is recursively replaced by a corresponding subordinate pattern depending on the designation of its parent. Notice that the F/B designation in the backward indexation is just the opposite direction to the forward indexation. This secures the smooth passage of all hexagons along the curve without any large leaps and crossings. The final hierarchical indexation based on the patterns from
Figure 9 is displayed in
Figure 10. A hash code consists of
$n\in \mathbb{N}\setminus \left\{0\right\}$ indices
$\overrightarrow{k}=({k}_{1},{k}_{2},\cdots ,{k}_{n})$, where
${k}_{i}\in \mathbb{N}$, addressing the Gosper islands containing a query point on each level
$i\in \{1,2,\cdots ,n\}$ of the hexagonal hierarchy. The indices of the upper hierarchical levels are represented by more significant trinities and the lower ones by less significant trinities. The hash code is computed as
$code={k}_{1}\xb7{2}^{3\xb7(n1)}+{k}_{2}\xb7{2}^{3\xb7(n2)}+\cdots +{k}_{n1}\xb7{2}^{3\xb71}+{k}_{n}\xb7{2}^{3\xb70}$. Inversely, an index
${k}_{i}$ can be obtained from
$code$ by simple bit operations. An index
${k}_{i}$ is a number from 0 to 6, but the three bits can represent maximally the number 7. Thus, there is unfortunately a numerical gap breaking the requirement of a contiguous sequence of indices (codes) stated in
Section 2.2. However, it does not have to be a crucial problem. While having a 64bit unsigned integer, a 21level hexagonal indexation can be defined.
3.3. Localization with NodeGosper Curves
As emphasized before, the hexagons are not hierarchically decomposable. However, the Gosper fractal (
Section 3.1) and NodeGosper indexation (
Section 3.2) are defined recursively in the topdown manner. At first, we define a topdown algorithm computing a centroid of hexagon hierarchically addressed by indices
$\overrightarrow{k}$. In the next section, we use this method to define the inverse algorithm mapping the points onto the NodeGosper SFC.
Let us consider the case of the base hexagon with
$size=1$ (
Figure 11), which is recursively replaced by the NodeGosper patterns (
Figure 9) up to the level
n. Given a vector of indices
$\overrightarrow{k}=({k}_{1},{k}_{2},\cdots ,{k}_{n1},{k}_{n})$ addressing a hexagon in a level
n Gosper island, a center point of such a hexagon is computed. This algorithm represents the backward mapping which verifies the bijectivity of the Gosper mapping.
The subordinate patterns can be indexed in the forward (F) or backward (B) manner (
Figure 9), which affects the addressing order of the hexagons by
$\overrightarrow{k}$. A pattern passing order F/B of the
ith recursion can be determined depending on
$\overrightarrow{k}$ as follows:
Each
${k}_{i}$ index has to be recalculated to index
${k}_{i}^{{}^{\prime}}\in \mathbb{N}$ in the F order (
Figure 9) to unify addressing of the corresponding Gosper islands in the topdown manner. The calculation of
${\overrightarrow{k}}^{{\phantom{\rule{0.166667em}{0ex}}}^{\prime}}=({k}_{1}^{{}^{\prime}},{k}_{2}^{{}^{\prime}},\cdots ,{k}_{n1}^{{}^{\prime}},{k}_{n}^{{}^{\prime}})$ is defined as follows:
For example, a point
$\overrightarrow{p}$ hashed onto indices
${\overrightarrow{k}}_{p}=(5,1)$ according to the level2 NodeGosper curve (
Figure 10) belongs to the hexagon 5 (
$Order\left(2\right)=B$) on the first hexagonal level (
$Order\left(1\right)=F$), whose subordinate island thus has reverse indexation of hexagons. Therefore, the corresponding index is 1 on the second level of recursion and not 5, as it would be according to the
F order, which means
${\overrightarrow{k}}_{p}^{{}^{\prime}}=(5,5)$. A pattern rotation is considered in the following transformations.
${\overrightarrow{k}}^{{\phantom{\rule{0.166667em}{0ex}}}^{\prime}}$ is used to compute the center point of the addressed hexagon. The algorithm recursively transforms two vectors: Position vector
${\overrightarrow{c}}_{i}$ and directional vector
${\overrightarrow{d}}_{i}$ (see
Figure 11), where
i is the current level of recursion. A vector
${\overrightarrow{c}}_{i}$ represents the initial center position of the current Gosper island. The vector
${\overrightarrow{d}}_{i}$ represents the rotation and scale of the grid on the
ith level of recursion. The initial directional vector is pointing to the neighboring hexagon and it is defined as
${\overrightarrow{d}}_{0}=(w,0)$, where
w is the width of the base hexagon. The
${\overrightarrow{d}}_{0}$ defines the basic orientation and distance between two neighboring hexagon centers before the first transformation. Depending on
${\overrightarrow{k}}^{{\phantom{\rule{0.166667em}{0ex}}}^{\prime}}$,
${\overrightarrow{d}}_{i}$ is defined by the recurrent formula:
where
$\frac{1}{\sqrt{7}}\xb7{R}_{\alpha}$ represents the scale by
$r=\frac{1}{\sqrt{7}}$ and rotation by the angle
$\alpha =arcsin\left(\frac{\sqrt{3}}{2\sqrt{7}}\right)$ (
Section 3.1), and the
${R}_{f\left({k}_{i1}^{{}^{\prime}}\right)}$ represents the additional rotation defined by (
1). The grid transformation can be simply defined by the following matrix:
Next, a vector
${{\overrightarrow{d}}_{i}}^{\phantom{\rule{0.166667em}{0ex}}{k}_{i}^{{}^{\prime}}}$ pointing to the specific neighboring hexagon addressed by
${k}_{i}^{{}^{\prime}}$ is defined as:
where
$\gamma \left({k}_{i}^{{}^{\prime}}\right)$ represents the corresponding angle by which
${\overrightarrow{d}}_{i}$ has to be rotated, so that the
${{\overrightarrow{d}}_{i}}^{\phantom{\rule{0.166667em}{0ex}}{k}_{i}^{{}^{\prime}}}$ points to the hexagon addressed by the
${k}_{i}^{{}^{\prime}}$ index.
$\gamma \left(y\right)$ is defined as:
where
$\gamma \left(y\right)$ equals to a multiple of
${60}^{\circ}$. The hexagon with
$y=0$ is initial, and therefore,
${\overrightarrow{d}}_{i}^{\phantom{\rule{0.166667em}{0ex}}0}={\overrightarrow{d}}_{i}$. For example,
${\overrightarrow{d}}_{i}$ is rotated by
${120}^{\circ}$ to obtain the second hexagon center
${{\overrightarrow{d}}_{i}}^{\phantom{\rule{0.166667em}{0ex}}2}$ (see
Figure 11).
The center point
${\overrightarrow{c}}_{i}$ is computed by a translation of
${\overrightarrow{c}}_{i1}$ by the properly rotated directional vector
${\overrightarrow{d}}_{i1}^{\phantom{\rule{0.166667em}{0ex}}{k}_{i1}^{{}^{\prime}}}$ as:
The center point ${\overrightarrow{c}}_{n}$ represents the final hexagon center addressed by indices $\overrightarrow{k}$.
3.4. NodeGosper Point Mapping
In the previous section, we described the algorithm computing a hexagon center according to $\overrightarrow{k}$. In this section, we define the inverse mapping of a point onto the NodeGosper curve, so that $\overrightarrow{k}$ is computed and the corresponding hash is generated.
The mapping onto the NodeGosper curve can be done only in the bottomup manner, because hexagons cannot be decomposed into subhexagons (
Figure 12). As it was explained in the previous sections, the hexagonal 7pattern (Gosper island) is rotated and scaled to replace a parent hexagon which defines the required hierarchy of hexagons. The constructed Gosper islands are nonconvex fractal tiles, so that they have to be fitted into neighboring islands to tile the plane. The topdown point localization is incorrect, because the jagged edges of islands overstep the borders of parent hexagons, so that a point previously localized in the hexagon (especially close to the edges) may belong to different branch of hierarchy in the next iteration (
Figure 12). An important fact about the hexagonal hierarchy is that seven hexagon centers of each NodeGosper pattern are always located inside their parent hexagon. It means that the upward hexagon centers localization defines numerically stable inverse procedure to the topdown algorithm and it secures the correct hierarchical assignment regardless of the jagged edges. There are still several problems that have to be solved:
To achieve both the correctness of hierarchical localization and recursive principles of the Gosper fractal, we separate the hashing algorithm into two phases. At first, we localize a point
$\overrightarrow{p}$ in the multiresolution hexagonal grid in the bottomup manner using the inverse formulas for the Gosper fractal construction (
Figure 12). The hierarchical localization gives us just a vector of indices defining the relative location of a point
$\overrightarrow{p}$ in the multiresolution grid. This step secures the correct localization inside the fractal shape of Gosper islands and we describe the procedure in detail in
Section 3.4.1. As the Gosper fractal is defined recursively, the specific pattern transformation and indexation for the different recursive branches can be computed only in the topdown manner. Thus, the indices returned by the first part of the algorithm have to be recursively recalculated in the topdown manner (see
Section 3.4.2). The second part of the algorithm returns the correct indices that are used to compute the final hash code defining the point order along the NodeGosper SFC.
3.4.1. Gosper Hierarchical Localization
The task is to determine the relative position of the current hexagon in the context of the parent hexagon. We ignore the difficulties with rotation and passage order in different branches of recursion for start. First, a point
$\overrightarrow{p}$ is localized in the level
n hexagonal grid (details in [
8,
43,
52]) using the matrix (
12) which returns the axial coordinates
${\overrightarrow{a}}_{n}\in {\mathbb{Z}}^{2}$ of the hexagon containing the point
$\overrightarrow{p}$. The next procedure computes only the relative transformation between axial coordinates which is independent on the specific
$size$ of hexagons. As mentioned before, the center points of hexagons can be reliably localized inside the parent hexagon. Thus, our transformation between levels
i and
$i1$ consists of three steps:
Calculation of hexagon center ${\overrightarrow{c}}_{i}$ according to axial coordinates ${\overrightarrow{a}}_{i}$.
Transformation of the ${\overrightarrow{c}}_{i}$ according to the orientation of the parent grid.
Localization of the transformed center point in the parent grid and calculation of the new axial coordinates ${\overrightarrow{a}}_{i1}$.
The superior grid of level
$(i1)$ should be scaled by
$\sqrt{7}$ and rotated by
$\alpha $. However, it is easier to preserve the same transformation matrix for calculation of all indices and alternatively transform the center point (scaled by
$\frac{1}{\sqrt{7}}$, rotated by
$+\alpha $), so the matrix
G (
6) is used instead. The transformation between levels
i and
$i1$ can be written as follows:
where
C is the matrix (
11) computing the center of a hexagon according to the axial coordinates,
${C}^{1}$ is the inverse matrix (
12) computing the axial coordinates from the center point and
G is the forward transformation matrix (
6) (read [
8,
43,
52] for details).
The final constant matrix
T is calculated as:
${\overrightarrow{a}}_{i}$ and
${\overrightarrow{a}}_{i1}$ are the integer axial coordinates of hierarchically corresponding hexagons at level
i and
$i1$. As the transformation matrix
T produces real unrounded coordinates, we denote the parent real axial coordinates as
${\overrightarrow{a}}_{i1}^{\mathbb{R}}\in {\mathbb{R}}^{2}$ that have to be rounded to the closest integers
${\overrightarrow{a}}_{i1}\in {\mathbb{Z}}^{2}$. Their hierarchical relationship with child axial coordinates
${\overrightarrow{a}}_{i}\in {\mathbb{Z}}^{2}$ can be derived as:
The Equation (
14) computes the transformed axial coordinates, but we also need to compute the hexagon index corresponding to the NodeGosper pattern described in
Section 3.2. Let the parent axial coordinates denote as
${\overrightarrow{a}}_{i1}^{\mathbb{R}}=({q}^{\mathbb{R}},{l}^{\mathbb{R}})$. They are recalculated to the cube coordinates as
${x}^{\mathbb{R}}={q}^{\mathbb{R}},{z}^{\mathbb{R}}={l}^{\mathbb{R}},{y}^{\mathbb{R}}={x}^{\mathbb{R}}{z}^{\mathbb{R}}$ according to the condition
${x}^{\mathbb{R}}+{y}^{\mathbb{R}}+{z}^{\mathbb{R}}=0$. The decimal part of coordinates represents the relative position between the child and parent hexagon. The relative decimal coordinates
${x}_{d}\in \langle 1,1\rangle $,
${y}_{d}\in \langle 1,1\rangle $,
${z}_{d}\in \langle 1,1\rangle $ are computed as:
As each hexagon center is close to one vertex and edge of the parent grid (see
Figure 12), the dominant axis
$dominant=max\{abs\left({x}_{d}\right),abs\left({y}_{d}\right),abs\left({z}_{d}\right)\}$ and its sign determine the index of the child hexagon in the view of the parent hexagon. The advantage is that this numeric transfer takes into account the negative coordinates of points, so that the dataset can be positioned anywhere in the space. The relative decimal coordinates
${\overrightarrow{v}}_{d}=({x}_{d},{y}_{d},{z}_{d})$ can be recalculated to the index
${b}_{i}=B\left({\overrightarrow{v}}_{d}\right)$ of the default pattern (
Figure 13 P1), where
$B\left({\overrightarrow{v}}_{d}\right)$ is defined as:
The threshold constant
$Thd\to 0$ represents some small decimal number (
$Thd={10}^{5}$ works well). As the coordinate transformation works on the level of a unitary grid, the method is numerically stable. The optimized algorithm is summarized in Algorithm 1.
Algorithm 1 Hierarchical point mapping 
Require: $\overrightarrow{v}=(x,y,z)$: cube coordinates of input point $\overrightarrow{p}$ $B\left({v}_{d}\right)$: transfers relative coordinates ${v}_{d}$ to index ${b}_{i}$ of the default pattern ( 16) T: transformation matrix ( 13) n: number of hierarchical levels Ensure: returns the indices $\overrightarrow{k}=({k}_{0},\cdots ,{k}_{n})$ of a point $\overrightarrow{p}$ {coordinate transformation from cube $\overrightarrow{v}$ to axial $\overrightarrow{a}$}
 1:
$\overrightarrow{a}.q=\overrightarrow{v}.x$, $\overrightarrow{a}.l=\overrightarrow{v}.z$ {for all levels}  2:
for i ← 1 to n do {transformation of axial coordinates $\overrightarrow{a}$}  3:
$\overrightarrow{a}=T\xb7{\left(\overrightarrow{a}\right)}^{T}$ {coordinate transformation from axial $\overrightarrow{a}$ to cube $\overrightarrow{v}$}  4:
$\overrightarrow{v}.x=\overrightarrow{a}.q$, $\overrightarrow{v}.z=\overrightarrow{a}.l$, $\overrightarrow{v}.y=\overrightarrow{v}.x\overrightarrow{v}.z$  5:
$\overrightarrow{a}.q=\left(INT\right)round(\overrightarrow{a}.q)$, $\overrightarrow{a}.l=\left(INT\right)round(\overrightarrow{a}.l)$ {decimal part ${\overrightarrow{v}}_{d}$ computation}  6:
${\overrightarrow{v}}_{d}.x=\overrightarrow{v}.x\left(INT\right)round(\overrightarrow{v}.x)$  7:
${\overrightarrow{v}}_{d}.y=\overrightarrow{v}.y\left(INT\right)round(\overrightarrow{v}.y)$  8:
${\overrightarrow{v}}_{d}.z=\overrightarrow{v}.z\left(INT\right)round(\overrightarrow{v}.z)$ {transfer to final index ${k}_{i}$}  9:
${k}_{ni}=B\left({v}_{d}\right)$  10:
end for

3.4.2. Index Conversion
Section 3.4.1 described a general method for hierarchical localization of a point
$\overrightarrow{p}$ in the level
n Gosper island. This section shows how to recalculate the default indexation model to other models. Especially, it defines a method solving the difficulties like pattern rotation and passage order to construct the correct NodeGosper SFC.
Let
$\overrightarrow{b}=({b}_{1},\cdots ,{b}_{n})$ be a vector of indices returned by Algorithm 1, where
n is the number of hierarchical levels. Each
${b}_{i}\in \u23290,6\u232a$ can be further transfered to final index
${k}_{i}=E(t,{b}_{i})$, where
$E(t,{b}_{i})$ is the function defined in
Table 1. The different indexation patterns are shown in
Figure 13 and their conversion is very simple. The final vector of indices
$\overrightarrow{k}=({k}_{1},\cdots ,{k}_{n})$ defines the hierarchical address of a hexagon in the Gosper island to define the final order of hexagons. Each
${k}_{i}$ can be represented by three bits, so all the indices are masked to the corresponding bits of hash according to the index significance (read
Section 3.2).
The procedure computing the correct NodeGosper curve is more complicated. There are two tasks:
The indices have to be hierarchically recalculated according to the rotation specified by patterns at different levels of recursion (see
Figure 9a).
The order of hexagons has to be hierarchically changed according to the forward and backward indexation (see
Figure 9b,c).
These properties have recursive nature and they cannot be solved by bottomup localization. The
$\overrightarrow{b}$ has to be recalculated to obtain the indexation model described in
Section 3.2. The whole method is described in Algorithm 2. Here, we summarize it in two steps:
As the patterns are rotated only by
$\pm {120}^{\circ}$ (
1), the rotation can be done by index shifting. The default indexation has the index 0 on the central hexagon and the indices 1–6 form a ring of hexagons. Let the
$rotDi{r}_{i}\in \{1,0,1\}$ be a number symbolizing the pattern rotation on the
ith level by
$\{{120}^{\circ},{0}^{\circ},+{120}^{\circ}\}$. The shifted index is computed as explained in Algorithm 2 (lines 2–11).
The passage order is reversed depending on the current pattern as explained in
Section 3.3. The algorithm is described in Algorithm 2 (lines 12–16).
Algorithm 2 NodeGosper index computation 
Require: $\overrightarrow{b}$: vector of default indices of input point $\overrightarrow{p}$ $E(t,{b}_{i})$: index transfer function defined in Table 1 $order=F$: passage order $rotDir=0$: rotation of the pattern ($rotDir\in \{1,0,1\}$) n: number of hierarchical levels Ensure: returns the indices $\overrightarrow{k}=({k}_{1},\cdots ,{k}_{n})$ of a point $\overrightarrow{p}$ {for all levels}
 1:
for i ← 1 to n do {rotation: shift of indices}  2:
if ${b}_{i}\ne 0$ and $rotDir\ne 0$ then  3:
${b}_{i}={b}_{i}+2\xb7rotDir$  4:
if ${b}_{i}<1$ then ${b}_{i}={b}_{i}+6$  5:
else if ${b}_{i}>6$ then ${b}_{i}={b}_{i}6$  6:
end if  7:
end if {transfer to NodeGosper basic pattern}  8:
${k}_{i}^{0}=E(P2,{b}_{i})$ {rotation calculation for next level}  9:
if ${k}_{i}^{0}\in \{0,3\}$ and ($rotDir<1$) then $rotDir=1$  10:
else if ${k}_{i}^{0}=5$ and ($++rotDir>1$) then $rotDir=1$  11:
end if {index order reversion}  12:
if $order=B$ then ${k}_{i}=6{k}_{i}^{0}$  13:
else ${k}_{i}={k}_{i}^{0}$  14:
end if {pattern passage order determination}  15:
if ${k}_{i}^{0}\in \{0,4,5\}$ then $order=(order=B\phantom{\rule{0.166667em}{0ex}}?\phantom{\rule{0.166667em}{0ex}}F:B)$  16:
end if  17:
end for
