Battle Analysis: Hexagon Library

The Hexagon Grid is a cartesian coordinate system is used for hexagon math.

The hexagons are given a hexagon point coordinate using the hexagon center location on the hexagon grid.

The hexsides are given a grid point coordinate using the middle of the hexside line on the hexagon grid.

The Hexagon Map Calculator calculates both the grid coordinate: and the hexagon point:

Now, analytic geometry is used for all math calculations.

1. Using the coordinates:

The hexagon point is used to calculate and display the hexagon name as the mouse moves into the hexagon.

The grid point is used to record terrain data.

The Hexagon Grid Calculator can determine if the grid coordinate is a center or a hexside.

The Hexagon Grid Calculator (docs) calculates the adjacent hexagon coordinates and the adjacent hexside coordinates.

2. Movement is calculated by adjusting the coordinates:

- North: 0,-4
- NE: +2,-2
- SE: +2,+2
- South: 0,+4
- SW: -2,+2
- NW: -2,-2

Note: The movement to adjacent hexagons DOES NOT require a check to see if the column is even or odd.

3. The adjacent hexsides are calculated by adjusting the coordinates from the hexagon center point:

- North: 0,-2
- NE: +1,-1
- SE: +1,+1
- South: 0,+2
- SW: -1,+1
- NW: -1,-1

Hexagon Name

The wargame map has labels on the hexagons to identify them.

The hexagon name is calculated from the hexagon point coordinate (x,y).

Note: This hexagon name is NOT a coordinate.

As the mouse moves, the hexagon point coordinate is calculated from the pixels on the map.

The Hexagon Grid is a simple cartesian x,y coordinate system used for wargame calculations.

hexagon point coordinate (x,y) → hexagon name

hexagon name → hexagon point coordinate (x,y)

Zone of Control ZOC

Zone of Control is calculated using the unit's hexagon point. Although the unit is placed on the map, the location of the unit is an attribute of the unit.

ZocCalculator.prototype.unitIsZOC = function(index) { var isZOC = false; var los = new LineOfSight(); var unitForce = this.force.getUnitForce(index); for (var i = 0; i < this.force.units.length; i++) { var force = this.force.getUnitForce(i); los.setOriginAndEndPoint(this.force.getUnitHexagonPoint(index), this.force.getUnitHexagonPoint(i)); if (los.getRange() == 1){ if(force != unitForce){ isZOC = true; break; } } return isZOC; }