## Wednesday, March 20, 2013

### The Value of Education

Yes, in fact, all that geometry they taught us in school is useful to me in my everyday life. It's just that my "everyday life" turns out to include writing little video games in my spare time.

The game I'm currently working on requires me to assemble and draw an tessellated group of hexagons. The program logic therefore needs to determine:
• The screen coordinates of a given hexagon
• The coordinates of the vertices representing the corners of a hexagon
• Whether or not two hexagons are adjacent
• Whether or not two hexagons are in the same position
• How to rotate a group of hexagons in 60-degree steps around a chosen "pivot" hexagon
The logic I wound up with is based on sort of a polar hexagon-based coordinate system. A coordinate pair consists of two numeric values, the first being the distance from a chosen "origin" hexagon, and the second being a rotational value. For instance, given a hexagonal grid and a chosen "origin" hexagon, you find the hexagon at coordinates (2, 5) by starting at the origin hexagon, moving two hexes in a pre-designated "north" direction, and then taking 5 steps clockwise in a circular direction around the origin hexagon.

This lets me perform my hex-group rotation operation fairly quickly, but presents a problem when I'm trying to determine whether two different locations in the hexagonal grid are adjacent to each other. I'm sort of cheating here by mapping my hexagonal coordinates to X-Y screen coordinates, and then checking the proximity of those coordinates to see if they are sufficiently close to one another to be adjacent hexagons.

My design document (a sheet of scrap paper sitting on my desk) is full of scribbled diagrams showing hexagons and vertices and congruent angles. It's good that all of the time I spent in school messing around with protractors and such is finally showing some benefit, but if I wind up designing a game that requires some calculus, I'm just going to integrate someone's math library. I honestly never want to see another integral sign again.