Hexagon spiral coordinates

 from Red Blob Games’s Blog
Blog post: 12 Mar 2025

My guide to hexagonal grids[1] is one of the most popular pages on my site. I keep a list of things I want to add to that page[2]. One of them has been spiral coordinate systems. I had thought I would wait until I actually use them in a real project, so that I would have real world experience with the thing I’m writing about. I’m afraid of writing about things I’m unsure about, or information that’s incomplete. But I haven’t used them yet.

I decided to stop waiting.

Spiral coordinates on a hexagonal grid

I decided to make some diagrams showing the parts I do understand. This also led me to try to understand more. I gave some unoptimized sample code. Part of me wanted to wait until I have the best sample code to present. But … I’ve already been waiting for so many years. I decided to publish the unoptimized code for now.

There are also lots of variants I could have covered: 0-based vs 1-based, outside-in vs inside-out, ring-based vs path-based, uniform direction vs alternating direction, single spiral vs recursive spirals, and probably more. But if I wait until I have figured out all of these, it will take even longer. So I published just one variant for now.

Take a look at the new section[3]. Please let me know what you’d like to see changed or improved!

While working on this, I also added an accidental discovery: running atan2(r,q) on axial coordinates instead of atan2(y,x) on cartesian coordinates produces something angle-like that can be used for sorting by angle, while being slightly cheaper than actually calculating the angles:

Something angle-like that can be used for sorting by angle

That’s not a topic I wanted for the main page, so I put it on a separate page[4].

Email me , or comment here: