📜 ⬆️ ⬇️

Introduction to the geometry of regular hexagons on the plane

Coordinate system setting
When implementing the movement of the map in games, it has recently become fashionable to use
for a space point of a regular hexagon (hex). It really solves a large number of issues. For example, does not require moving through the corners of a polygon. Six directions for movement is quite sufficient to convey the realism of movement.

Coordinate system
Fig.1. Coordinate system
Note that for fixing points on the map, using the Cartesian coordinate system that is so familiar to us becomes unprofitable, since the position of each individual cell becomes difficult to identify without using fractional values ​​in the coordinates, which makes the calculations heavier. Equally non-trivial will be the calculations of the distances between the cells, the calculation of the action of the obstacles during the shot and with it. Thus, the first thing you need to do is choose a convenient coordinate system. The fact that moving to a neighboring cell would correspond to a shift by a single value along one axis of the coordinate grid would significantly simplify the calculations.
Sector
Fig.2. Sectors formed by coordinate axes
A close look at the options for the vector directions of the axes is most convenient for me to see the one where the angle between the directions of the axes corresponds to 120 °. 3 coordinate axes correspond to 6 directions of motion.
Such a system is redundant as long as every point in space.
can be described in an infinite number of ways, each of which becomes a trajectory of movement from the origin to a point, but the shortest path is described in a single way by a projection onto the nearest coordinate axes. In fact, we get 6 sectors representing 3 pairs, in each of which the description of points located in them is carried out through 2 coordinate axes adjacent to it as shown in Fig.2.
Coordinates of points
Fig.3. Coordinates of points
In this view, the coordinates of the points will be fixed as shown in Fig.3.
Convert coordinate to normal view
Normal, we will call such a record coordinates, when it describes the shortest path to it from the origin, which corresponds to the projections on nearby coordinate axes.

To determine that the coordinate is in normal form, we can distinguish several properties inherent in it:

')

Source: https://habr.com/ru/post/794/


All Articles