Battle Analysis: Hexagon Library

map

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:

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:


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;
	  }