Created
September 12, 2015 20:35
-
-
Save dbrockman/03bdb8980a41e7f0da86 to your computer and use it in GitHub Desktop.
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 characters
/** | |
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 }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment