brian@radio.astro.utoronto.ca (Brian Glendenning) (12/19/89)
This is probably a simple question. Imagine that 2-D space has been tiled with hexagons. Given a point (x,y), how can I quickly assign a "hexagon number" to that point, where the "hexagon number" uniquely identifies that hexagon (I don't care about any other properties of the hexagon number other than it be unique). Thanks! Brian -- Brian Glendenning - Radio astronomy, University of Toronto brian@radio.astro.utoronto.ca uunet!utai!radio!brian glendenn@utorphys.bitnet
gilmore@vms.macc.wisc.edu (Neil Gilmore) (12/24/89)
In article <BRIAN.89Dec19121404@radio.astro.utoronto.ca>, brian@radio.astro.utoronto.ca (Brian Glendenning) writes... >This is probably a simple question. Imagine that 2-D space has been >tiled with hexagons. Given a point (x,y), how can I quickly assign a >"hexagon number" to that point, where the "hexagon number" uniquely >identifies that hexagon (I don't care about any other properties of >the hexagon number other than it be unique). Thanks! Quite right, it is a simple question. In 4-directional grid systems (like pixel bitmaps, et al.) it is easy to assign a unique number to each of the rectangular units by the formula number = column * (row * maxcolumn), where row and column are the coordinates of the rectangle, and maxcolumn is the largest value which column can take. Understandably then, to move to any adjacent rectangle is accomplished merely by adding an offset to the current rectangle number, 1 to go right, -1 to go left, maxcolumn to go down, -maxcolumn to go up (assuming the orientation of a pixel bitmap, with the origin in the upper left). 6-directional planes are quite similar. Consider a plane of hexagons in which the 'straight' direction is horizontal. The hexagon number is then, as before number = column * (row * maxcolumn), column being measured from the extreme left of the plane. However, the movement functions become somewhat more complex. The offsetsd are: 1 to move right, -1 to move left, maxcolumn + odd(row) (assuming true has a numerical value of -1), maxcolumn - even(row), -maxcolumn + even(row) to move diagonally up and left, -maxcolumn - odd(row) to move diagonally up and right. A vertically oriented system uses similar offsets. >Brian >-- > Brian Glendenning - Radio astronomy, University of Toronto >brian@radio.astro.utoronto.ca uunet!utai!radio!brian glendenn@utorphys.bitnet +-----------------------------------------------------------------------+ | Kitakaze Tatsu Raito Neil Gilmore internet:gilmore@macc.wisc.edu | | Jararvellir, MACC, UW-Madison bitnet: gilmore@wiscmac3 | | Middle Kingdom Madison, Wi | +-----------------------------------------------------------------------+