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 which is marked in the third coordinate of anchor.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 which is marked in the third coordinate of anchor.
(cell->anchor g cell)
(cell->anchor g q r)
Converts cell coordinates (q,r) to anchor coordinates (x,y).
Converts cell coordinates (q,r) to anchor coordinates (x,y).
(cell->mid g cell)
(cell->mid g x y)
Converts cell coordinates (q,r) to mid point (x,y).
Converts cell coordinates (q,r) to mid point (x,y).
(coords->anchor g coords)
(coords->anchor g x y)
Converts 2d coordinates (x,y) to cell anchor (x,y).
Converts 2d coordinates (x,y) to cell anchor (x,y).
(coords->cell g coords)
(coords->cell g x y)
Converts 2d space coordinates (x,y) to cell coordinates (q,r).
Converts 2d space coordinates (x,y) to cell coordinates (q,r).
(coords->mid g coords)
(coords->mid g x y)
Converts 2d space coordinates (x,y) into cell midpoint (x,y).
Converts 2d space coordinates (x,y) into cell midpoint (x,y).
(corners g coords)
(corners g coords scale)
(corners g x y scale)
Returns list of cell vertices for given 2d space coordinates.
Returns list of cell vertices for given 2d space coordinates.
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.
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