hexagonal-tiles

Algorithm to generate a hexagonal grid with coordinate system

走远了吗. 提交于 2019-11-26 15:32:51
问题 I am trying to roll up 19 lines of code into a single for loop, but I am feeling a bit stumped. The reason I ask, is because I want the grid to be other sizes instead of 5. In Main::drawHexGridAdvanced() , I am trying to deduce the similarities between each line as opposed to Main::drawHexGridBasic() where I am hard-coding values. I am not sure how to determine the start of the x for each column in each row, because the pattern for n == 5 is 0, -1 -2 -2 -2 after that each consecutive column

Generating triangular/hexagonal coordinates (xyz)

假装没事ソ 提交于 2019-11-26 15:18:49
问题 I'm trying to come up with an iterative function that generates xyz coordinates for a hexagonal grid. With a starting hex position (say 0,0,0 for simplicity), I want to calculate the coordinates for each successive "ring" of hexagons, as illustrated here: So far, all I've managed to come up with is this (example in javascript): var radius = 3 var xyz = [0,0,0]; // for each ring for (var i = 0; i < radius; i++) { var tpRing = i*6; var tpVect = tpRing/3; // for each vector of ring for (var j =