Answer the question
In order to leave comments, you need to log in
Coordinate grid and distances in hexes?
There is a field of hexes.
You need to choose a coordinate system (x, y) and calculate the formula for the distances between two hexes for it.
Advise the option that will be closest to human perception.
Answer the question
In order to leave comments, you need to log in
A person immediately identifies three directions (see the figure below). Therefore, you can choose an oblique coordinate system (in the figure: red lines - horizontal direction and oblique) with an angle of 60 °. Then along the red direction resp. the coordinate will increase, and along the blue - two at the same time. The distances between the centers will be calculated by the formula
Where G is the Gram matrix of this oblique-angled system:
This is the case when the distances between the centers of the neighbors are 1.
Use standard 2D Cartesian coordinate system. The only feature, there are prohibited provisions.
Pluses
1) It is clear and natural. There are even forbidden states in our world (Pauli principle).
2) The distance is calculated by the formula = sqrt( (x1-x0) ^ 2 + (y1-y0) ^ 2 )
3) If x1!=x0 and y1!=y0, then these are different coordinates (unlike the three-component system)
If by distance you mean the minimum number of transitions between two adjacent hexes, forming a continuous path from one hex to another, then everything is very simple. The abscissa axis is drawn in the usual way, horizontally, the ordinate axis is drawn at an angle of 60 ° to it. The distance between the hexes (x 1 , y 1 ) and (x 2 , y 2 ) is calculated as follows:
In a question like this, “approaching the human version” is reflected in the speed of work.
If you are not a pervert, then you will use some kind of breadth-first search algorithm. And, oddly enough, it is optimal to apply it over a one-dimensional representation.
for my game on Canvas, I also drew a similar field :) with the only difference that I have it rotated 90 degrees. coordinate system is 2-dimensional. X - as usual, Y snakes. to work with this normally, you have to divide Y into even and odd, but this is a payment for hexagons. to determine where they clicked, I had to remember trigonometry, but everything is more or less simple there. The most important thing is not to forget anything :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question