Hexagon Coordinates
MapGrid: screen pixels to hexagon and hexpart coordinates
A grid is placed over the map to create new coordinates. The grid will not be displayed while playing the wargame. It will be used by the MapGrid object.
A programming object called MapGrid is created to convert the screen pixels to the grid's coordinates.
As the mouse moves over the map, the MapGrid object will locate a MapGrid rectangle. The MapGrid rectangles are used
to indicate when the mouse is over the hexagon center or a hexagon hexside.
It's not perfect, but good enough for
a workable wargame play-aid.
mapgrid.js javascript code MapGrid.cs C# code
Hexagon: hexagon coordinates with hexagon name
A programming object called Hexagon is created to save an adjusted hexagon coordinate. If mouse is over a hexside, the mouse is checked to see if it is above or below the hexside line. Then, the hexagon coordinate is adjusted (0, -2) or (0, +2) or (+1, -1) or (-1, +1) or (+1, +1) or (-1, -1).The Hexagon object has a function to convert the hexagon coordinates into the wargame's hexagon numbering system.
hexagon.js javascript code Hexagon.cs C# code
Movement calculations are easy now.
To move, the coordinates change:
| Direction | x axis | y axis |
| North | +0 | -4 |
| NorthEast | +2 | -2 |
| SouthEast | +2 | +2 |
| South | +0 | +4 |
| SouthWest | -2 | +2 |
| NorthWest | -2 | -2 |
Hexpart: hexagon/hexside coordinates
A programming object called Hexpart is created to save the hexside coordinates.
When not on an hexside, the coordinates will mark the hexagon center.
hexpart.js javascript code Hexpart.cs C# code
Hexpart coordinates can be used for range, bearing, and line of sight.
They are integers that are easier to use in wargame calculations.
Terrain on the map is stored in an array or database using the integer (x, y) as an index.
Cartesian coordinates
Hexpart coordinates and Hexagon can be converted to Cartesian coordinates for geometry calculations.
Just multiply the x-axis by 3 and the y-axis by √3
Now, the whole world of analytical geometry is available when needed.
formula for the distance between two points is:
d = √(x2-x1)2 + (y2-y1)2
To find the distance between 0101 and 0402:
0101 is 12, 8√3 and 0402 is 30, 14√3 in cartesian coordinates
d = √(30 - 12)2 + (14√3 - 8√3)2
d = √(18)2 + (6√3)2
d = √(324 + 108)
d = √432
d = √(144)*√3
d = 12√3
The length of the hexagon edge to edge is: 4√3
d = 12√3 divided by 4√3 = 3 hexagons long
Here are the parameters needed to setup a mapGrid object.
The map offset is how far away the edges of the map are from the 0, 0 origin.