S
S
Sergey2011-05-22 17:33:10
Mathematics
Sergey, 2011-05-22 17:33:10

Coordinate grid and distances in hexes?

There is a field of hexes.
HexX-SeekM.100.jpg
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

5 answer(s)
Y
youngmysteriouslight, 2011-05-22
@GAmoVeR

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
image
Where G is the Gram matrix of this oblique-angled system: image
This is the case when the distances between the centers of the neighbors are 1.

V
vinxru, 2011-05-22
@vinxru

Use standard 2D Cartesian coordinate system. The only feature, there are prohibited provisions.
image
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)

O
Oleg Torbasov, 2011-05-22
@torbasow

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:

  • denote for simplicity δx = x 2  − x 1 and δy = y 2  − y 1 ;
  • for δy ≥ 0 distance ρ ((x 1 , y 1 ), (x 2 , y 2 )) =
    • δx + δy if δx > 0;
    • δy if − δy ≤ δx ≤ 0;
    • − δx if δx ≤ − δy.

  • For δy < 0, we rearrange the points or, which is the same, re-denote δx = − δx and δy = − δy, after which we apply the same formula.

V
Vitaly Zheltyakov, 2011-05-22
@VitaZheltyakov

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.

J
joger, 2011-05-23
@joger

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 question

Ask a Question

731 491 924 answers to any question