Skip to content

The object of storing and working with a hexagonal matrix

License

Notifications You must be signed in to change notification settings

m9studio/HexagonMatrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Hexagon Matrix

The "HexagonMatrix" object is a hexagonal matrix, where x, y and z are the coordinates of the cells. If we talk about the matrix in more detail, then at least 1 value of x, y or z must be equal to or less than the value 0;

How the matrix works:

  1. To determine the coordinates, we use 3 parameters x, y and z. Also, we have a Radius that is equal to the maximum value of x, y and z;

  2. In the usual representation, the hexagon matrix looks like this: 1

  3. For convenient storage, we need to divide it into 7 sectors: 2

  4. As a result, we get 3 square matrices, 3 arrays and an object in the center, the coordinates of which will be x <= 0; y <= 0; z <= 0; 3

  5. These examples show how to take data from a hexagonal matrix:

  6. Getting data from a square matrix

obj.Get(2, 3, 0);
obj.GetXY(2, 3);

//this function call will not be an error
obj.Get(2, 3, -1);

Also works with "Set" methods. 4 8) Getting data from an array

obj.Get(0, 0, 3);
obj.GetZ(3);

//this function call will not be an error
obj.Get(-2, -1, 3);

Also works with "Set" methods. 5 9) Getting the central data

obj.Get(0, 0, 0);
obj.GetCenter();

//this function call will not be an error
obj.Get(-2, 0, -1);

Also works with "Set" methods. 6 11) The example uses Radius 4.
12) If x, y and z all have values greater than 0 or greater than the "Radius" value, then the "Get" method will return "null", and the "Set" method will return "false".