
Hexagonal Grids - Red Blob Games
Another way to look at hexagonal grids is to see that there are three primary axes, unlike the two we have for square grids. There's an elegant symmetry with these. Let's take a cube grid and slice out a diagonal plane at x + y + z = 0. This is a weird idea but it helps us with hex grid algorithms:
Hexagonal Grids - Red Blob Games
Each direction on the hex grid is a combination of two directions on the cube grid. For example, northwest on the hex grid lies between the +y and -z, so every step northwest involves adding 1 to y and subtracting 1 from z.
Implementation of Hex Grids - Red Blob Games
May 6, 2015 · The main page covers the theory for hex grid algorithms and math. Now let’s write a library to handle hex grids. The first thing to think about is what the core concepts will be. Since most of the algorithms work with cube coordinates, I’ll need a data structure for cube coordinates, along with algorithms that work with them.
Grid pathfinding optimizations - Red Blob Games
Mar 2, 2014 · For grids, we typically use distance as the heuristic. It’s greater than 0, but less than the shortest path length, so it gives us shortest paths, but not the best speed. For maps in general, not only grid maps, we can analyze the map to generate better heuristics. Pick a set of pivot points and then find the shortest paths between them. The ...
Implementation of Hex Grids - Red Blob Games
May 6, 2015 · The main page covers the theory for hex grid algorithms and math. Now let’s write a library to handle hex grids. The first thing to think about is what the core concepts will be. Since most of the algorithms work with cube coordinates, I’ll need a data structure for cube coordinates, along with algorithms that work with them.
More pixel to hex approaches - Red Blob Games
This works because a regular hex grid also happens to satisfy the Voronoi property: the hexagon contains all points that are closer to its center than to any other hexagon center. Unlike the geometric algorithms listed above, guess and test doesn’t …
Hexagon Shaped Hex Map Storage - Red Blob Games
Apr 30, 2023 · Also see Hex Directions, which divides the hexagon into six areas instead of the three here, based on whether q, r, or s is the largest. Another way to store a hexagonal shaped hex grid is to use spirals [3] , either counting from the outside [4] or counting from the inside [5] .
Hexagon directions - Red Blob Games
Apr 21, 2018 · Hex grids have six primary directions. Look at the max of | {{labels.s}} - {{labels.q}} |, | {{labels.r}} - {{labels.s}} |, | {{labels.q}} - {{labels.r}} |, and it will tell you which wedge you're in.
Hex region borders - Red Blob Games
Sometimes you want to outline a region on a hex grid. Here are two techniques for that. Both of these techniques also work on other convex polygon maps, including square grids and triangle grids but also irregular polygons like voronoi diagrams.
Introduction to the A* Algorithm - Red Blob Games
A grid map can use a non-grid pathfinding graph, or vice versa. A* runs fastest with the fewest graph nodes; grids are often easier to work with but result in lots of nodes. This page covers the A* algorithm but not graph design; see my other page [4] for more about graphs.