That's neat. I spend my work days simulating advanced nuclear reactors that have hexagonal fuel assemblies. In my codes I've used a lot of this info. This is an excellent resource that I'll be referring people who come from the more traditional square lattice world.
The grid is usually rectangular, and I've always found this a bit odd: hexagons represent 2-d sphere packing, so they always seemed more natural to me. I once asked researchers in the field about this, around 2006, and they responded that rectangular grids serve just as well. I just found this paper from 2007 where apparently hexagonal grids fare better:
This makes me wonder, for realistic models that are meant to model a notion of neighbour cells, why aren't we always using hexagonal grids in 2d or higher-dimensional analogues? With rectangular grids, you're always faced with the choice of defining whether touching on edges and corners count as neighbours or not, which seems like an unnatural choice. Why, then, does this not seem to matter in the end?
If rotational symmetry is important to the dynamics, you're likely to do much better on coarse grids with a hex layout, because it has a finer rotational symmetry.
Of course, with a small-enough grid rotational symmetry should be restored (or you've chosen a poor discretization!). One might rephrase your statement as: the lattice artifacts / discretization errors vanish faster on a hex grid. Could be.
When I worked on fire-spreading models [0] the grids we used were square. I would wager that this is because it makes thinking significantly easier. In my current field[1], square lattices are chosen because of the underlying supercomputing architecture. The communication mesh in tera- and petascale computers tend to be rectangular [2]. At these scales, having a nice rectangular layout of the local subvolumes simplifies communication algorithms and can provide a dramatic speedup---in this case having fewer neighbors is better.
[0]: In high school I implemented the fact that fires burn faster uphill while working for David Keyes on http://www.cs.cmu.edu/~caliente/
Square grids are more intuitive: they map to our standard cardinal and ordinal directions. As long as you treat the ordinal neighbours (the corners) as being sqrt(2) away from the center (as oppposed to 1 away from the center like the cardinal neighbours, or all of the hexagonal neighbours) then you don't get spatial distortions.
I can provide an intuitive thought picture answer, that if you're doing something that boils down to numerical integration under a curve, a pile of hexagons or other polygons will win over a simple raster array of square pixels at a similar quantity of polygons, but when implemented, if its computationally cheaper to run the rectangular raster array at 10, 100, maybe 1000 times the resolution of the hexagon implementation, then the raster will always win at the overall systemic level at the numerical integration game. Not implying forest fires are simple numerical integration games, but they are similar-ish in trying to discrete-ize a non-discrete analog problem.
If you were talking about EE DSP stuff, you'd call it quantization noise. Theoretically a floating point A/D converter would be nice / interesting if such a thing existed, but in practice you minimizing that noise source by using more fixed bits per sample.
As far as I know the reason why square lattices are preferred over hex lattices is that they can easily generalized to 3D, ... . If you invest lots of time thinking about good, say, FEM or Finite Volume algorithms, you want to have results that can easily generalized afterwards.
As a part of my university coursework I modeled forest fires with a grid but mine had varying densities of forests and each tree affected an area around it, not just adjacent cells. It's a really interesting thing to try and model if you get a chance, because tiny adjustments can make a world of difference.
Fascinating! One of Affirm's old job application puzzles was about a hexagonal grid. I did a write-up[1] of how I solved it, unaware that I was reinventing the wheel. The cube coordinates abstraction would have been killer for being able to explain things to myself.
Thanks! (I'm actually in the middle of a major update to the page — I hope to have it published in a few weeks)
I used d3.js for this page (and most of the pages on my site).
For a given shape of map (rectangular, triangular, hexagonal, parallelogram, etc.) I generate a set of cube hex coordinates. I then use d3 to instantiate an SVG shape for each coordinate. D3 will maintain the mapping from the cube coordinate to the SVG shape, so I can set element classes on mouse events, and then I style those with CSS.
For example, in the line drawing example, I have a generic function that creates a hexagonal shaped grid (of hexagons)[1]. On mouseover, I figure out which hex it is, then run the line drawing algorithm to create a set of coordinates from the start point to the hex you're pointing to. I then tell d3 to iterate over all the SVG dom nodes and set the "selected" class if it's in the set returned by the line drawing routine[2]. The color changes with the CSS rule #diagram-line .selected polygon {fill: hsl(200, 50%, 80%); }
I've used canvas for some of the pages but I find svg much easier to work with. I can attach mouse events to the elements, and I can set properties (such as color) easily without redrawing everything. D3 is great for maintaining a mapping from data (such as a set of hex coordinates) to dom nodes (such as a set of svg <polygon>s). D3 also has transitions, but I think most of my needs could be handled with CSS transitions instead of D3's JS transitions.
The offset approach is what most people do. I've used it too. It makes the storage simpler for rectangle shaped maps but the algorithms more complicated (and slower). I wrote this page to present the alternative coordinate systems. The symmetry of the cube system greatly simplifies many of the algorithms, so it's often easier to convert offset or axial to cube, run the algorithm, and then convert the answer back to offset or axial. The main downside of axial is that map storage in an array is a little more complicated; http://www.redblobgames.com/grids/hexagons/#map-storage
I've explored similar questions using a grid of equilateral triangles. Obviously they are very close in spirit. I wonder though, if the triangles are somehow more basic.
The triangular grid is dual to the hexagonal grid -- if you take a hexagonal grid, put a vertex in the center of each hexagonal tile, then form tile edges by connecting each vertex to its six neighboring vertices, you get a triangular grid. Doing the same operation to the triangular grid gives you the hex-grid back again.
I wonder what a non-cubic polyhedron-based voxel system would look like, without going all the way to marching cubes/tetrahedrons (where the cubes/tetrahedrons are only part of the algorithm that helps in rendering basically arbitrary voxels).
Wow, I've been trying to make a Settlers of Catan game for fun and the thing I struggle most with is the board algorithms. This a fantastic resource to help with that, thanks.
[+] [-] acidburnNSA|11 years ago|reply
[+] [-] jordigh|11 years ago|reply
http://en.wikipedia.org/wiki/Forest-fire_model
The grid is usually rectangular, and I've always found this a bit odd: hexagons represent 2-d sphere packing, so they always seemed more natural to me. I once asked researchers in the field about this, around 2006, and they responded that rectangular grids serve just as well. I just found this paper from 2007 where apparently hexagonal grids fare better:
http://www.sciencedirect.com/science/article/pii/S0307904X06...
This makes me wonder, for realistic models that are meant to model a notion of neighbour cells, why aren't we always using hexagonal grids in 2d or higher-dimensional analogues? With rectangular grids, you're always faced with the choice of defining whether touching on edges and corners count as neighbours or not, which seems like an unnatural choice. Why, then, does this not seem to matter in the end?
[+] [-] evanb|11 years ago|reply
Of course, with a small-enough grid rotational symmetry should be restored (or you've chosen a poor discretization!). One might rephrase your statement as: the lattice artifacts / discretization errors vanish faster on a hex grid. Could be.
When I worked on fire-spreading models [0] the grids we used were square. I would wager that this is because it makes thinking significantly easier. In my current field[1], square lattices are chosen because of the underlying supercomputing architecture. The communication mesh in tera- and petascale computers tend to be rectangular [2]. At these scales, having a nice rectangular layout of the local subvolumes simplifies communication algorithms and can provide a dramatic speedup---in this case having fewer neighbors is better.
[0]: In high school I implemented the fact that fires burn faster uphill while working for David Keyes on http://www.cs.cmu.edu/~caliente/
[1]: Lattice QCD codes use a (4D spacetime) rectangular lattice https://usqcd-software.github.io/
[2]: The BlueGene/Q, for example, is a 5-dimensional rectangular torus.
[+] [-] rcfox|11 years ago|reply
[+] [-] VLM|11 years ago|reply
If you were talking about EE DSP stuff, you'd call it quantization noise. Theoretically a floating point A/D converter would be nice / interesting if such a thing existed, but in practice you minimizing that noise source by using more fixed bits per sample.
[+] [-] wolfgke|11 years ago|reply
[+] [-] JonRB|11 years ago|reply
[+] [-] tiler|11 years ago|reply
[+] [-] akanet|11 years ago|reply
[1]: http://vincentwoo.com/2013/03/08/above-and-beyond-the-affirm...
[+] [-] ims|11 years ago|reply
https://news.ycombinator.com/item?id=5809724
[+] [-] jxf|11 years ago|reply
Tangentially, I'd love to know the best way to create the visuals for this kind of content. I assume no one's writing all those SVGs by hand, right?
[+] [-] amitp|11 years ago|reply
I used d3.js for this page (and most of the pages on my site).
For a given shape of map (rectangular, triangular, hexagonal, parallelogram, etc.) I generate a set of cube hex coordinates. I then use d3 to instantiate an SVG shape for each coordinate. D3 will maintain the mapping from the cube coordinate to the SVG shape, so I can set element classes on mouse events, and then I style those with CSS.
For example, in the line drawing example, I have a generic function that creates a hexagonal shaped grid (of hexagons)[1]. On mouseover, I figure out which hex it is, then run the line drawing algorithm to create a set of coordinates from the start point to the hex you're pointing to. I then tell d3 to iterate over all the SVG dom nodes and set the "selected" class if it's in the set returned by the line drawing routine[2]. The color changes with the CSS rule #diagram-line .selected polygon {fill: hsl(200, 50%, 80%); }
I've used canvas for some of the pages but I find svg much easier to work with. I can attach mouse events to the elements, and I can set properties (such as color) easily without redrawing everything. D3 is great for maintaining a mapping from data (such as a set of hex coordinates) to dom nodes (such as a set of svg <polygon>s). D3 also has transitions, but I think most of my needs could be handled with CSS transitions instead of D3's JS transitions.
[1] See http://www.redblobgames.com/grids/hexagons/Grid.hx : hexagonalShape() [2] See http://www.redblobgames.com/grids/hexagons/ui.js : makeLineDrawer()
[+] [-] antichaos|11 years ago|reply
[+] [-] novaleaf|11 years ago|reply
a regular 2d array, but with every-other row logically offset by 50% of the cells width, thus you end up with:
super simple data structure (normal 2d array), and pathfinding isn't difficult (use hex algos). I wonder why nobody ever writes about this....Edit: ahh, the article kind-of describes this in the "Offset coordinates" section, just no explicit mention of able to use an array for storage.
[+] [-] amitp|11 years ago|reply
[+] [-] baxter001|11 years ago|reply
[+] [-] gameshot911|11 years ago|reply
[+] [-] leni536|11 years ago|reply
http://en.wikipedia.org/wiki/Penrose_tiling
[+] [-] scott_karana|11 years ago|reply
[+] [-] MarkHarmon|11 years ago|reply
https://github.com/mark-harmon/HexPixiJs
[+] [-] dublinclontarf|11 years ago|reply
[+] [-] prestonbriggs|11 years ago|reply
[+] [-] panic|11 years ago|reply
[+] [-] lloeki|11 years ago|reply
To wit: http://mathworld.wolfram.com/Space-FillingPolyhedron.html
[+] [-] fit2rule|11 years ago|reply
[+] [-] maccard|11 years ago|reply
http://www.redblobgames.com/pathfinding/a-star/introduction....
[+] [-] tericho|11 years ago|reply
[+] [-] nness|11 years ago|reply
[+] [-] bhhaskin|11 years ago|reply
[+] [-] ofcapl_|11 years ago|reply
[+] [-] pocketstar|11 years ago|reply
[deleted]