Created
September 12, 2015 20:35
-
-
Save dbrockman/03bdb8980a41e7f0da86 to your computer and use it in GitHub Desktop.
Revisions
-
David Brockman Smoliansky created this gist
Sep 12, 2015 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,57 @@ /** Axial coordinates # convert cube to axial q = x r = z # convert axial to cube x = q z = r y = -x-z # convert cube to even-q offset q = x r = z + (x + x&1) / 2 # convert even-q offset to cube x = q z = r - (q + q&1) / 2 y = -x-z # convert cube to odd-q offset q = x r = z + (x - x&1) / 2 # convert odd-q offset to cube x = q z = r - (q - q&1) / 2 y = -x-z # convert cube to even-r offset q = x + (z + z&1) / 2 r = z # convert even-r offset to cube x = q - (r + r&1) / 2 z = r y = -x-z # convert cube to odd-r offset q = x + (z - z&1) / 2 r = z # convert odd-r offset to cube x = q - (r - r&1) / 2 z = r y = -x-z **/ export function cubeToAxial(x, z) { return { q: x, r: z }; } export function axialToCube(q, r) { return { x: q z: r y: -q - r }; }