6 ms·
Hexagonal Grids (2013)
- furyofantares 6y agoI love this page. I've used this page as a reference, it saved me a lot of time and left me with a stronger understanding as well. It reminds me of old school web. When google first came on the scene I was amazed at how many informational pages from either hobbyists or professionals existed (but which I wasn't finding with older search engines), where someone just decided to put everything they know about some topic into a page in glorious detail.
- hoten 6y agoHis page about map generation is an invaluable resource for game developers.
- amitp 6y agoYes, old school web! A few of the others I like: https://faculty.evansville.edu/ck6/tcenters/ https://faculty.evansville.edu/ck6/tcenters/ ; http://paulbourke.net/ http://paulbourke.net/ ; https://pomax.github.io/bezierinfo/ https://pomax.github.io/bezierinfo/ ; https://www.fieggen.com/shoelace/ https://www.fieggen.com/shoelace/ ; https://www.wood-database.com/ https://www.wood-database.com/ ; http://www.oftenpaper.net/sierpinski.htm http://www.oftenpaper.net/sierpinski.htm ; https://www.animatedknots.com/ https://www.animatedknots.com/ . There are lots more out there but social media favors new content rather than timeless content. I want to see more pages like that so, following “Be the change that you wish to see in the world”, I am writing informational pages.
- swsieber 6y agoI remember this page. I used it almost a decade ago when implementing a settlers of catan clone for that was going to be the main project for a class curriculum. I was a TA/RA at the time. It's a great page. It was invaluable to me.
- xenihn 6y agoAny chance you still have that project/curriculum? Would love to see it.
- swsieber 6y agoI don't think I do. Though it might be hidden on a hardrive somewhere. I didn't do the curriculum so much as the "reference" implementation. This was for BYU CS 340. If you search those on GitHub you can probably find some students' implementations. The whole class was about working as a group and design patterns.
- shwestrick 6y agoSuch an invaluable resource! I spent many hours here while helping develop https://hexiconapp.com/ https://hexiconapp.com/. The axial coordinate system, in particular, makes working with hexagons much simpler.
- rgovostes 6y agoSee also several past discussions, though none recent: https://hn.algolia.com/?dateRange=all&page=0&prefix=true&query=redblobgames.com%20hexagons&sort=byPopularity&type=story https://hn.algolia.com/?dateRange=all&page=0&prefix=true&que...
- type_enthusiast 6y agoThis is from 2013, so I guess it comes up every so often (2019: https://news.ycombinator.com/item?id=19184412 https://news.ycombinator.com/item?id=19184412). But, I've had it bookmarked since the first time I saw it come up. It's a great article for anyone who's ever played a hexagonal game or has thought about making a hexagonal game. The source site also has a lot of great stuff on applications of computer science to less-thought-of aspects of game development (by which I mean people usually think of pixel-blasting 3D engines as "game development", but there's a lot more to it)
- devsquid 6y agoThis is cool. I recently wrote an A* pathfinding system for a hex based game. Choosing a good coordinate system 100% makes this easier.
- rendall 6y agoWhich one did you go for?
- devsquid 6y agoI went with what they call the "Axial coordinates". I think the alternative, "Cube coordinates", causes a lot of issues and confusion when writing game logic.
- rendall 6y agoMy imagination fails when I attempt to think of a good reason for using the 'offset' coordinates. If someone knows of one, I'd be open to hearing it, but I suspect that it makes things quite tricky
- ChrisMarshallNY 6y agoThat’s useful! Thanks for posting it. I don’t need to do this too often, but I like having choices.
- xipho 6y agoThis just came up a bit ago in another thread. RBG is so good. Like I did a while back I'll mention that that work is the reason I could write this Ruby svg viz library https://github.com/SpeciesFileGroup/waxy https://github.com/SpeciesFileGroup/waxy and it be a fun, rather than painful process.
- Timothee 6y agoAh, I wish I had come across this two weeks ago! I've been doodling with Processing and was working on hexagonal Truchet tiles. (basically random tiles that have paths connecting to any random tiles next to it, with hexagons as tiles instead of squares) I ended up having to figure out some of that stuff again, in particular the coordinate system inside each tile so that I could deal with integer coordinates and translate them into the right fraction of the radius. It was fun to figure out what I needed, so I don't regret it :) And I am also planning on doing something with cubes, so this page will come in handy. Thanks for sharing! I love how it covers all aspects of the problem. Result of the tiling: https://twitter.com/_timothee/status/1330315929641570304 https://twitter.com/_timothee/status/1330315929641570304 Diagram of my coordinate system: https://twitter.com/_timothee/status/1327859098642046976 https://twitter.com/_timothee/status/1327859098642046976
- thewebcount 6y agoSweet! I love Truchet Tiles. (Did you know Truchet was a priest in the 18th century?[0]) I see that Apple's Motion has a Truchet tile generator[1], too. [0] https://en.wikipedia.org/wiki/Sébastien_Truchet https://en.wikipedia.org/wiki/Sébastien_Truchet [1] https://support.apple.com/en-afri/guide/motion/motn5d6778a0/mac https://support.apple.com/en-afri/guide/motion/motn5d6778a0/...
- taywrobel 6y agoI almost never use bookmarks any more, but I’ve had this page bookmarked for the better part of a decade now and still refer to it at least once a year, and I don’t even work in game development.
- joshu 6y agoi've used this guide several times. hooray!
- Groxx 6y agoRed Blob Games has quite a few excellent blog posts. I highly recommend checking out the rest of their blog :)
- aidenn0 6y agoFWIW, I strongly prefer square grids for tabletop games. Hexagonal grids give you precise measurements in exactly 6 directions. If you approximate sqrt(2) as 1.5 then square grids give you pretty darn accurate measurements in 8 directions, including 2 pairs of directions that are orthogonal, which is good for rectangular features like buildings. Furthermore the distance between two points can be quickly calculated with (long-side + 1/2 short-side), which is doable in your head, unlike the distance calculation on a hex grid. Lastly, if you divide the circle into a large number of slices and calculate the average error for path distance using hex or squares, among those slices, the average error (compared to pythogorean) is smaller with squares (obviously for small multiples of 6 and small multiples of 8 respectively, one or the other will be preferred).
- jghn 6y agoI always found the hex grid useful in Battletech as your facing has an impact on where you get hit and having 6 sides provides more potential combinations of facing.
- aidenn0 6y agoI find 8 facing directions (4 sides, 4 corners) to be sufficient, but I suppose a hexagon gives you 12 (6 sides, 6 corners).
- rrobukef 6y agoOn the other hand, for movement along the 8 directions the distance is 41% short, for movement along the 4 main directions, the taxicab distance is 41% longer than the actual distance. For a hexagonal grid, the distance is approximated by counting the number of cells of the shortest path. This has <10% relative error (IIRC) from the actual distance.
- alisonkisk 6y agoIf you take diagonals to be 1.5, then distances are <10% high. The half-short-side heuristic (sqrt(aa + bb) ~= a + b/2) makes taxicab very close to correct for non-square distance as well.
- yudlejoza 6y agoFor a semi-goofy take (CGPGrey) on hexagons: https://youtu.be/thOifuHs6eY https://youtu.be/thOifuHs6eY
- smexxymoose 6y agoCame to the comments just for this link
- amitp 6y agoHexagons are bestagons!
- wumms 6y agoMore hexagons in nature: Image: "Hexagonal formations on the surface of the Salar de Uyuni (Bolivia, 3,656 meters above sea level) [0] as a result of salt crystallization from evaporating water": https://en.wikipedia.org/wiki/Salar_de_Uyuni#/media/File:Salar_Uyuni_au01.jpg https://en.wikipedia.org/wiki/Salar_de_Uyuni#/media/File:Sal... "During the rainy season (December to March) the salt flat gets covered with a layer of water. As the water evaporates under largely still conditions, the salt forms hexagonal shapes (optimal for heat transfer) on its surface known as Bénard cells, an example of the Rayleigh–Bénard convection [1] phenomena." [2] [0] https://en.wikipedia.org/wiki/Salar_de_Uyuni https://en.wikipedia.org/wiki/Salar_de_Uyuni [1] https://en.wikipedia.org/wiki/Rayleigh%E2%80%93B%C3%A9nard_convection https://en.wikipedia.org/wiki/Rayleigh%E2%80%93B%C3%A9nard_c... [2] https://commons.wikimedia.org/wiki/File:20170809_Bolivia_1581_Uyuni_sRGB_(26204506689).jpg https://commons.wikimedia.org/wiki/File:20170809_Bolivia_158...
- amitp 6y agoAlso in nature: there is a giant hexagon on Saturn! http://www-cs-students.stanford.edu/~amitp/diagrams/saturn-hexagon/ http://www-cs-students.stanford.edu/~amitp/diagrams/saturn-h...
- jsjohnst 6y agoSurprised they didn’t cover hexagonal ring data structures. Here[0] is a visualization along with the calculations needed to find nearest neighbors. [0] https://www.flickr.com/photos/jeremyjohnstone/3979747216/ https://www.flickr.com/photos/jeremyjohnstone/3979747216/
- cookiengineer 6y agoEvery time I see a post of redblobgames, I realize what a treasure this website is. I've been on this website so often, and pointed other people so many times to it... I hope this never gets lost and is archived. If Amit would write a book about gamedev, I'd definitely buy it and add it to my collection.
- neilfrndes 6y agoUber's H3 geospatial library uses a lot of these concepts. https://eng.uber.com/h3/ https://eng.uber.com/h3/
- mrtnmcc 6y agoIn case anyone is doing signal processing on a hexagonal grid, the https://en.wikipedia.org/wiki/Hexagonal_fast_Fourier_transform https://en.wikipedia.org/wiki/Hexagonal_fast_Fourier_transfo... is pretty useful. I work on consumer phased arrays with hexagonal grids, so the HFFT is useful for computing the far-field beam pattern.
- wycy 6y agoThis guide was incredibly helpful a few years ago for one of the Advent of Code challenges.
- keyle 6y agoThe guides on that website are fantastic. I wrote multiple games using them as reference. Well written, explained clearly and a wealth of information.
- swayvil 6y agoAre you familiar with the kisrhombille grid? https://en.wikipedia.org/wiki/Truncated_trihexagonal_tiling#Kisrhombille_tiling https://en.wikipedia.org/wiki/Truncated_trihexagonal_tiling#... Scaleable like a square grid. 12 directions.
- michaericalribo 6y agoAn added challenge is to efficiently construct hex grids by hand——quickly, at the expense of accuracy. I didn’t have access to a printer early in the pandemic, but wanted to put together maps for a tabletop rpg. This is a clever solution: http://www.rdwarf.com/users/wwonko/hex/irregular/ http://www.rdwarf.com/users/wwonko/hex/irregular/ It has the added benefit of being easy to remember
- bransonf 6y agoAnd if you want something cool to do with this, try implementing Gliński's variant of chess. It’s something I’m dabbling in, but no doubt an order of magnitude more difficult to implement than orthodox chess. The idea of indexing by cubes is so obvious once you discover it, but maybe not as easy to intuit. Same goes for the data structures.
- elihu 6y agoCGP Grey did a video about hexagons recently. I mean, there's only so much you can say about hexagons really, but he manages to cover a lot of ground. https://www.youtube.com/watch?v=thOifuHs6eY https://www.youtube.com/watch?v=thOifuHs6eY
- amitp 6y agoA surprise to be on HN! Tech notes for the curious: I started the page in 2013 based on notes I had been collecting for ~20 years before that. I update this reference page as I come up with better visualizations and explanations. The last major update was in 2018 when I rewrote it from using d3.js to using vue.js. It greatly reduced the amount of code I was writing, and also let me make the page more interactive. I then added lots more (doubled coordinates, links to papers, axes legends, diagonal directions, side by side comparisons) and improved most of the existing sections. In 2019 the changes were minor, rewriting the map storage section and improving performance. In 2020 I improved the cube/hex animation, the pixel-to-hex section, and added Rust sample code. There's lots more I could add to the page[1] but I don't have any specific plans for when I'll get around to it. The page is svg- and js-heavy. I prerender the diagrams on the server (try loading it without js!). Then using IntersectionObserver on each section of the page, I swap the static diagrams and text with interactive versions. This improves load times somewhat, because almost no JS has to run on page load. For printability I process the page with xsltproc, extract all the links, and turn them into footnotes. Try print preview on the page to see these. Unfortunately the diagrams are broken when printing in Chrome (it works in Firefox) so I need to investigate. [1]: https://www.notion.so/redblobgames/f8bc2f44fba94607afa9c06711d23245?v=0766432cb1534ce582ce35b33cbbef7e&p=7d2d4d624bc5483dafbe615d75ab3902 https://www.notion.so/redblobgames/f8bc2f44fba94607afa9c0671...
- privatemonkey 6y agoThis is a wonderfull source. Very well written. I'm happy to see it on Hacker News. A few years since I used it last. Didn't know you had rewritten it but I see now the updates you've done, especially in interactivity. I'll continue to use this as my main reference point for hex grids, especially now that I've picked up pace on my virtual tabletop project. Good work!! Thanks
- Calloutman 6y agoThanks for the resource. I'm pretty sure I used it for some of my simulations of C60 molecules hexagonal packing, during my physics PhD a few years back.
- simonh 6y ago
- dang 6y agoIf curious see also 2019 https://news.ycombinator.com/item?id=19184412 https://news.ycombinator.com/item?id=19184412 2017 https://news.ycombinator.com/item?id=14627711 https://news.ycombinator.com/item?id=14627711 2015 https://news.ycombinator.com/item?id=9537009 https://news.ycombinator.com/item?id=9537009 2015 https://news.ycombinator.com/item?id=8941588 https://news.ycombinator.com/item?id=8941588 Discussed at the time: https://news.ycombinator.com/item?id=5809724 https://news.ycombinator.com/item?id=5809724
- payelsarkar28 6y agoHi
- payelsarkar28 6y agoHello
- goldenkey 6y agoIn case you want to make a hexagonal cellular automata: https://github.com/churchofthought/HexagonalComplexAutomata https://github.com/churchofthought/HexagonalComplexAutomata Or in WebGL: https://github.com/churchofthought/Grautamaton/tree/complex https://github.com/churchofthought/Grautamaton/tree/complex
- rcarmo 6y agoThis is an awesome resource I keep going back to now and again for the sheer fun of it. Glad to see it on HN again (it’s well worth reposting occasionally for folk who haven’t seen it yet).
- darkwinx 6y agothis web site is amazing!!
- willis936 6y agoGood stuff. I’m surprised that I have not seen a voxel-based game that leverages a purely 2D render and expects the player to switch between projections to work with the area.