Range, Bearing and Line of Sight

map


 

Range

The range can be calculated with a simple algorithm.

First, find the distance between the x1, x2 coordinates and the distance between the y1, y2 coordinates

ΔX = abs ( x2 - x1 ) and ΔY = abs( y2 - y1 )

If ΔX > ΔY Then range = ΔX / 2

Else range = (ΔX + ΔY) / 4

Bearing

The bearing number is a number from 0 - 24.
For even numbers, it is the actual bearing divided by 15
For odd numbers, it is the area between the even bearing lines

The bearing number is usually used to determine frontal/flank attacks and checking field of fire angles.

los.js javascript code  Los.cs C# code( HexpartLos.cs )

Even numbers are
0 = N 0 ° degrees
2 = 30 ° degrees
4 = 60 ° degrees
6 = E 90 ° degrees
8 = 120 ° degrees
10 = 150 ° degrees
12 = S 180 ° degrees
14 = 210 ° degrees
16 = 240 ° degrees
18 = W 270 ° degrees
20 = 300 ° degrees
22 = 330 ° degrees

Line of Sight hexagon list

If the line of sight is straight off the hexagon side


If the bearing is 0, step 0, -4 in hexparts
If the bearing is 4, step +2, -2 in hexarts
If the bearing is 8, step +2, +2 in hexparts
If the bearing is 12, step 0, +4 in hexarts
If the bearing is 16, step -2, +2 in hexparts
If the bearing is 20, step -2, -2 in hexarts

the hexsides are just half of the above values

 

If the line of sight is straight off the hexagon corner

corner map


If the bearing is 2, step +2, -6 in hexparts
If the bearing is 6, step +4, 0 in hexarts
If the bearing is 10, step +2, +6 in hexparts
If the bearing is 14, step -4, 0 in hexarts
If the bearing is 18, step -2, +6 in hexparts
If the bearing is 22, step -2, -6 in hexarts

the hexsides are just half of the above values

 

 

 

 

If the line of sight zig zags

If the bearing is 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23

check the 2 possible hexagons by comparing the distance of the hexagon centers to the line of sight line.

Whichever hexagon center is closest, choose it.

see explanation below

 

From Analytical Geometry, there is a formula to calculate the distance from a point to a line.  Since the coordinates can be converted to geometry, we can use the formula to calculate the distance of a point from a line. We will compare two offsets.
For each point (x,y) the x is multiplied by 3 and the y is multiplied by √3 to convert to cartesian coordinates.
Since the denominator is the same for each offset, we can multiply both offsets by the denominator. This will work because we are not trying to find the exact distance, but rather to find out which offset is smaller.   We can now also factor out 3√3 in the numerator. The formula boils down to an offset function.

offset =
abs(x1*y2 - x1*y0 - x2*y1 + x2*y0 + x0*y1 - x0*y2)

x1, y1 is the origin of the line. 
x2,y2 is the endpoint of the line
x0, y0 is the coordinate of the point being tested

 

For example: hexagon 0104 (4,20) to hexagon 0302 (8,12)
The 2 possible hexagons to check are 0103 (4,16) and 0203 ( 6,18)

x1, y1 is the origin of the line.  x2,y2 is the endpoint of the line

x0, y0 is the coordinate of the point being tested From hexagon 0104, we need to choose between 0103 or 0203

For the first check of hexagon 0103  x1,y1 = 4,20  x2,y2 = 8,12  x0,y0 = 4,16

the offset check is abs( 4*12 - 4*16 - 8*20 + 8*16 + 4*20 - 4*12 )
     = abs( 48 - 64 - 160 + 128 + 80 - 48) = 16

For the second check of hexagon 0203 x1,y1=4,20  x2,y2=8,12  x0,y0 = 6,18

the offset check is abs( 4*12 - 4*18 - 8*20 + 8*18 + 6*20 - 6*12)
     = abs( 48 - 72 - 160 + 144 + 120 - 72) = 8

We pick the lessor value 0203

Continue on up the LOS line checking. 

The hexside coordinate (x, y) between the 2 hexagons
  can be calculated from (x1 + x2)/2 and (y1+y2)/2,

Brute force, the only way.

See the example map at the top of the page. Click on the los.js code to see the algorithm.