Any maths boffs? Hexagon grid help request

Soldato
Joined
20 Jun 2010
Posts
3,251
I am working on a hexagon array grid system and am stuck wrapping my head around this little problem, see diagram bellow:



Essentially, given a point (p, q) i want to transform in to an addressable array space, (a, b, c), determined by the magnitude and direction of the perpendicular lines that bisect the axis

Any help much appreciated
 
I hope I havent misinterpreted what u want...

For each line, you just need the perpendicular distance d from point A (p,q,0) to a vector V (x,y,0) which defines the line. The equation is just:

d = |A x V| / |V|

Note that x means cross-product, not multiply. Take the modulus to get magnitude of top and bottom. Its easier than normal because all lines go through the origin, so A is also a vector to the point. note that you need to do the maths in 3D to get the cross product to work, so use z=0;
 
Last edited:
Yes its effectively 2-D space, with a redundant set of axes, where any 2 new coordinates (rotated by 120 degrees) define the original x, y coordinates.

I was assuming that the OP wants to store the hexagons in a data array.
In which case there would be impossible combinations like [1,1,6] which would have to store a null value surely?

I accept that I might be on completely the wrong track :p
 
I think OP just wants the floating point values of a, b, c. So the mapping is from
x, y => a, b, c (for any x, y)

Or I may be wrong. OP - are you there??

Yes, floating point values are fine. There may be a fixing function to snap the values to the centre of the containing hexagon.

I am not sure I understand the diagram,why do you need to use three coordinates for a 2d hex grid?

In short, because its fun :p

I was assuming that the OP wants to store the hexagons in a data array.
In which case there would be impossible combinations like [1,1,6] which would have to store a null value surely?

I accept that I might be on completely the wrong track :p

Its a fair point, so i will probably use a hash map of viable values instead of a cubic array.

edit: I fully accept i may be barking up a tree here. Its good sport.
 
Last edited:
Back
Top Bottom