惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
D
DataBreaches.Net
F
Fortinet All Blogs
阮一峰的网络日志
阮一峰的网络日志
博客园_首页
Apple Machine Learning Research
Apple Machine Learning Research
H
Help Net Security
M
MIT News - Artificial intelligence
美团技术团队
人人都是产品经理
人人都是产品经理
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Cloudflare Blog
有赞技术团队
有赞技术团队
L
LangChain Blog
博客园 - Franky
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
博客园 - 【当耐特】
S
SegmentFault 最新的问题
V
Visual Studio Blog
Blog — PlanetScale
Blog — PlanetScale
Hugging Face - Blog
Hugging Face - Blog
B
Blog
I
InfoQ

Red Blob Games: latest blog posts

Red Blob Games: English: a vs an Red Blob Games: Differential heuristics Red Blob Games: Responsive design calculator Red Blob Games: Academic citations Red Blob Games: Highlighting interactive code blocks Red Blob Games: Optimizing page size Red Blob Games: Writing a guide to SDF fonts Red Blob Games: URLs with trailing punctuation Red Blob Games: What I did in 2025 Red Blob Games: Goodbye Sass Goodbye Sass Red Blob Games: RotMG map seeds Red Blob Games: Mapgen4 Mapgen4's use of WebGL2 Red Blob Games: Mapgen4 river shader Red Blob Games: Mapgen4 renderer Red Blob Games: Harnessing ChatGPT hallucinations Red Blob Games: Let Let's write a search engine, part 2 of 2 Red Blob Games: Let Let's write a search engine, part 1 of 2 Red Blob Games: Hexagon conversions Red Blob Games: Mapgen4 trade routes Red Blob Games: De-optimizing mapgen4 Red Blob Games: Thoughts on Flash Red Blob Games: What I did in 2024 Red Blob Games: Hexagon page animations Red Blob Games: SDF Halos SDF Halos Red Blob Games: SDF headless tests, part 2
Red Blob Games: Hexagon spiral coordinates
2025-03-13 · via Red Blob Games: latest blog posts
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].