Skip to content

Instantly share code, notes, and snippets.

@jonikorpi
Last active December 5, 2018 13:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonikorpi/af5a8362388cd28e9f6cdd9a82ebc5b6 to your computer and use it in GitHub Desktop.
Save jonikorpi/af5a8362388cd28e9f6cdd9a82ebc5b6 to your computer and use it in GitHub Desktop.
Getting the pointy hex coordinates of a hex region's center hex in this arrangement: https://www.redblobgames.com/grids/hexagons/#wraparound (Both the input and output are in "cube" hex coordinates. r is the radius of the regions.
const cubeCoordinatesToRegionCenter = (x, y, z, r) => {
const centerX = x * 2 * r + x + r * z;
const centerZ = z * -2 * r - z - x + -r * x;
return [centerX, -centerX-centerZ, centerZ];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment