[Math] Converting map coordinates of a rotated grid.

coordinate systems

I'm trying to makes a stellar map, but I'm using a coordinate system different from the standard. I have coordinates in the normal system, but I need them in mine. This equates to rotating the carteesian grid 45 degrees.

Worst case scenario I can just brute force this, but I'd rather just be able to convert with an equation so I'm looking for how to convert a position's x,y coordinate from one grid to another grid when the difference between the two grids are one is spun clockwise so that centerlines are at a 45 degree angle to each other.

side note: Because I don't know if they original coordinates are south or north oriented, the rotation may actually be rotated 225 degrees rather than just 45.

Best Answer

Rotation matrices is basicaly what you want.

For rotating a vector $\begin{pmatrix} x \\ y \end{pmatrix} $ by the angle $\alpha$, just multiply it with the matrix $\begin{pmatrix} \cos(\alpha) &-\sin(\alpha) \\ \sin(\alpha) &\cos(\alpha) \end{pmatrix}$.

\begin{align} \begin{pmatrix} x_{new} \\ y_{new} \end{pmatrix} &= \begin{pmatrix} \cos(\alpha) &-\sin(\alpha) \\ \sin(\alpha) &\cos(\alpha) \end{pmatrix} \cdot \begin{pmatrix} x_{old} \\ y_{old} \end{pmatrix} \\ &= \begin{pmatrix} x_{old} \cdot \cos(\alpha) - y_{old} \cdot \sin(\alpha) \\ x_{old} \cdot \sin(\alpha) + y_{old} \cdot \cos(\alpha) \end{pmatrix} \end{align}

In case you are not familiar with vectors, this means:

\begin{align} x_{new} &= x_{old} \cdot \cos(\alpha) - y_{old} \cdot \sin(\alpha) \\ y_{new} &= x_{old} \cdot \sin(\alpha) + y_{old} \cdot \cos(\alpha) \end{align}

Related Question