Skip to main content

Coordinate system for tiling with hexagons.

Project description

Hexa-tiling

Coordinate system for tiling with hexagons.

What does the grid look like?

Explaining illustration

How does it work?

Rings and angles

The grid can be viewed as accumulation of concentric rings. On the image, the origin is labelled 0, surrounded by the ring #1 composed of tiles 1-6, surrounded by the ring #2 composed of tiles 7-18.

Numbering

Tiles are numbered from 0, in increasing order, starting at the origin (center of the grid), spiraling around the origin, with the first tile of each ring at 0°.

Coordinates

Polar coordinates can be used to find a tile. Each tile has a radius and an angle.

  • The radius is the distance to the origin, corresponding to the rank of the ring the tile belongs to.
  • The angle, in degrees, is measured between the direction "noon" (or "up", "north", etc) and the position of the tile.

The maths behind it

Ring length (Perimeter)

Let the ring length be $P$ and its rank $n$.

$$P(0) = 1$$

$$P(1) = 6$$

$$\forall n > 1, \quad P(n) = 2P(n-1)$$

$$\forall n > 0, \quad P(n) = 6 * 2^{n-1}$$

Grid size (Area)

Let the number of tiles for a grid with $n$ rings be $A$.

$$A(n) = \sum^{n}_{i = 0}{P(i)}$$

$$= 1 + \sum^{n}_{i = 1}{6 * 2^{i-1}}$$

$$= 1 + 6 * \sum^{n-1}_{i = 0}{2^{i}}$$

$$= 1 + 6 * (2^n - 1)$$

$$= 6 * 2^n - 5$$

Number from coordinates

Let the number of a tile be $X$, its radius $n$ and its angle $\alpha$.

$$X(0, \alpha) = 0$$

$$\forall n > 0, \quad X(n, \alpha) = A(n - 1) + \frac{\alpha}{360}P(n)$$

$$= 6 * 2^{n-1} - 5 + \frac{\alpha}{360}*6 * 2^{n-1}$$

$$= 6 * 2^{n-1}(1 + \frac{\alpha}{360}) -5$$

Radius

To find the radius $n$ given the number $X$:

$$X = 0 \Leftrightarrow n = 0$$

$$0 \le \alpha < 360$$

$$\implies \forall n > 0, \quad X(n, 0) \quad \le \quad X(n,\alpha) \quad < \quad X(n, 360)$$

$$\implies \forall n > 0, \quad A(n - 1) + \frac{0}{360}P(n) \quad \le \quad X \quad < \quad A(n - 1) + \frac{360}{360}P(n)$$

$$\implies \forall n > 0, \quad A(n - 1) \quad \le \quad X \quad < \quad A(n - 1) + P(n) = A(n)$$

$$\implies \forall n > 0, \quad 6 * 2^{n-1} - 5 \quad \le \quad X \quad < \quad 6 * 2^n - 5$$

$$\implies \forall n > 0, \quad 2^{n-1} \quad \le \quad \frac{X + 5}{6} \quad < \quad 2^n$$

$$\implies \forall n > 0, \quad n-1 \quad \le \quad \log _2(\frac{X + 5}{6}) \quad < \quad n$$

$$\implies \forall n > 0, \quad n = \lfloor \log _2(\frac{X + 5}{6}) \rfloor + 1$$

Angle

Tile 0 has no angle.

$$\forall n > 0, \quad X(n, \alpha) = 6 * 2^{n-1}(1 + \frac{\alpha}{360}) -5$$

$$X + 5 = 6 * 2^{n-1}(1 + \frac{\alpha}{360})$$

$$\frac{X + 5}{6 * 2^{n-1}} = 1 + \frac{\alpha}{360}$$

$$360(\frac{X + 5}{6 * 2^{n-1}} - 1) = \alpha$$

$$360(\frac{X + 5}{6 * 2^{\lfloor \log _2(\frac{X + 5}{6}) \rfloor + 1-1}} - 1) = \alpha$$

$$360(\frac{X + 5}{6 * 2^{\lfloor \log _2(\frac{X + 5}{6}) \rfloor }} - 1) = \alpha$$

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xtiler-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xtiler-0.1.0-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

Details for the file xtiler-0.1.0.tar.gz.

File metadata

  • Download URL: xtiler-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for xtiler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 74d883180f6cd830b4ae82238cbc0585f92d473037a8f9e783ac37cc783c68e9
MD5 80f7ed9237b1cc5b5d6de4db74ca1de3
BLAKE2b-256 8d472b1b41f4e724eea0582d8782a9eebaa37ab90ca240764bd801859f98f26c

See more details on using hashes here.

File details

Details for the file xtiler-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: xtiler-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for xtiler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 843e94f2ef06a41026e6f161e451b1a57a9ad3fa2d371d331cc662a113178bcc
MD5 75f6e83120cc1655d2bdc0b3036df2a8
BLAKE2b-256 22b30b3d397cef4a36c709d4c6a628b6ec276976a5df62342f28346a33e95885

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page