Grid calculation functions.
Convert 2d coordinates into various grid coordinates and back.
Terms used:
Each grid is defined by cell type and size. Optionally you can provide translating vector.
Each cell has it's own coordinates, mostly axial based (only square has offset).
For hexagonal cell size is a radius from midpoint to corner. For the rest it is the size of the side.
Cell types are:
:square
:shifted-square
:triangle
:rhombus
:flat-hex
- flat topped:pointy-hex
- pointy toppedq
coordinate. Even q
is pointy topped, odd q
is flat topped.Grid calculation functions. Convert 2d coordinates into various grid coordinates and back. Terms used: * cell type - grid cell shape: square, triangular, hexagonal, rhomboidal * coords - 2d euclidean coordinates (x,y) * cell - cell coordinates (q,r) * anchor - cell position in 2d euclidean space * corners - shape vertices * size - size of the cell. ### Grids Each grid is defined by cell type and size. Optionally you can provide translating vector. Each cell has it's own coordinates, mostly axial based (only square has offset). For hexagonal cell size is a radius from midpoint to corner. For the rest it is the size of the side. Cell types are: * `:square` * `:shifted-square` * `:triangle` * `:rhombus` * `:flat-hex` - flat topped * `:pointy-hex` - pointy topped ### Notes * Hexagonal grids are based on https://www.redblobgames.com/grids/hexagons/ * Only hexagonal cells have anchor at the center. For the rest the anchor is at the top left vertex. * Anchors for triangular grids are shared between two cells: even and odd `q` coordinate. Even `q` is pointy topped, odd `q` is flat topped.
(cell->mid g cell)
Converts cell coordinates to mid point
Converts cell coordinates to mid point
(coords->anchor g coords)
Converts 2d coordinates to cell anchor.
Converts 2d coordinates to cell anchor.
Function which returns vertices for flat topped hexagon for given size and coordinates.
Function which returns vertices for flat topped hexagon for given size and coordinates.
(grid)
(grid type)
(grid type size)
(grid type size sx sy)
Create grid for given type, size and optional translating vector.
Create grid for given type, size and optional translating vector.
Common grid conversion functions.
Common grid conversion functions.
(cell->anchor g cell)
Converts cell coordinates to anchor coordinates.
Converts cell coordinates to anchor coordinates.
(coords->cell g coords)
Converts 2d space coordinates to cell coordinates.
Converts 2d space coordinates to cell coordinates.
(coords->mid g coords)
Converts 2d space into cell midpoint.
Converts 2d space into cell midpoint.
(corners g coords)
(corners g coords scale)
Returns list of cell vertices for given 2d space coordinates.
Returns list of cell vertices for given 2d space coordinates.
(grid-type g)
Returns type of the cell.
Returns type of the cell.
Function which returns vertices for pointy topped hexagon for given size and coordinates.
Function which returns vertices for pointy topped hexagon for given size and coordinates.
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close