Hexagon Grid
in
Programming Questions
•
1 year ago
I'm trying to think of a simple way to make a hexagonal grid and my best guess is to use a double for loop as one would do with rects() but spaced appropriately (and obviously represented by hexagons). The problem I run into with this is the appropriate amount to move the hexagons down every row.
If I am using a unit triangle (an equilateral triangle where every side has a length of 1.0) then the height should be 0.866025403784439. Six equilateral triangles make a hexagon. I found this height by using the pythagorean theorem:
a*a = b*b + c*c
a = 1.0
b = 0.5
1.0*1.0 = 0.5*0.5 + c*c
1.0 = 0.25 + c*c
0.75 = c*c
c = sqrt(0.75)
c = 0.866025403784439
So I guess I have two questions:
1. How much of this information can a float use? (What is the maximum decimal information a float can have)
2. Is there a better way to do this?
It may be worth noting I am interested in being able to tell which hexagons touch each other. My goal is to make a hexagonal Game of Life.
1