Last active
December 5, 2018 13:44
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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