# Hexagon Coordination System Rotation Problem

I am working on a hexagon tiles game and I have applied a coordination system to it.

There are two types and hexagon tiles pattern, and my one is look like this: Hexagon Tiles Coordination

*please noticed that for some reasons, the x and y axis here are swapped, x is vertical and y is horizontal, please feel free to swap it back if you want.

In this pattern, using (0,0) as center, you can see it actually have 6 directions. I set the right hand side ((0,1) side) is 0 degree, and we have 60, 120, 180, 240, 300, etc. (rotate clockwise or anti-clockwise are both ok, but i use anti-clockwise here)

Say, I have a unit on (0,1), and I want it to move anti-clockwise with (0,0) as the center, that is, move to (1,1). It is easy to view it graphically, but quite no idea how to calculate it by a formula.

This is getting more difficult when the case extended to d2 and d3 (means the distance from center)

Hexagon Coordination rotation - d1 to d3

So, is there any ways that can calculate what is the new coordinates after rotate anti-clockwise by 60 degrees? or for all degrees? Thanks!

The problem you're running into is that you're only kind of forcing an orthogonal coordinate system on your hexagonal array.

The even $y$ rows are offset relative to the odd $y$ rows. When you rotate $\pi/3$, whether a hexagon ends up in an even or odd row depends on the evenness/oddness of $y$.

Maybe that observation is enough to lead you to a formula for rotations of some multiple of $\pi/3$.

But for arbitrary rotations (as well as the rotations just discussed), you'll be better served by using a skew coordinate system. One axis is your current $y$ axis; the other would be $\pi/3$ off from this axis. Your indices would change, but you wouldn't have the offset effect that you have now with the even and odd rows. The indexing would match the symmetry of your layout better.

• Thanks for your inspiration on the skew coordinate system! It really give me a new way to think of the whole system~! Aug 26, 2016 at 3:07
• I will try to reorganize all the stuff relate to the game (e.g. path-finding function, distance finding, etc.) and then try to deal with the rotation problem. I will update you guys if I fix it! Thanks! Aug 26, 2016 at 3:17

I have found a solution of the rotation issues.

As John said, I have to applied another coordination system for the rotation. Instead of using a Skew Coordination System, after I have read the guidlines in Amit Patel's Home, I have decided to use the Cube coordination System.

I strongly recommend everybody that need a Hexagonal tile coordination system to take a look into this site, it just have everything you need!

To summarize, the final approach I choose is: 1. Use simple "offset coordination system" to create all the tile (just like what I did in the question, but I swapped the x and y back) 2. Generate "Cube Coordination System" for all the tiles 3. Use the cube coordinate to process to get the coordinate after rotation, then convert it back to simple "offset coordination system".

There is also an answer in here, which also answered by Amit Patel.