Calculate new tile coordinates for 90 degree rotated square object

377 Views Asked by At

So I have a square (all sides even) with even AxA tiles (for example 3x3). Every tile has its x,y coordinates according its placement. After I rotate the object by 90 degrees around the center, the these world coordinates are no more valid (see image). So what I'm trying to figure out is a formula that takes 3 parameters: 1) old coordinates (x,y), 2) tile count (A) and 3) rotate direction.. and gives new nx,ny after 90 degree rotation. For example 1,1 after rotation becomes 1,3.. 3,2 become 2,1.. 2.2 stays 2.2 and so on. Any help appreciated.

enter image description here

1

There are 1 best solutions below

17
On BEST ANSWER

You need the rotation matrix centered at $(2,2)$

$\begin{bmatrix}x'\\y'\end{bmatrix} = \begin{bmatrix}2\\2\end{bmatrix} +\begin{bmatrix}\cos \theta & -\sin \theta \\ \sin \theta &\cos \theta\end{bmatrix} \begin{bmatrix}x-2\\y-2\end{bmatrix}$

EDIT

To clarify, this is in the sense that anti-clockwise rotations are positive, for clockwise rotations, just put the same angle, but negative.

EXAMPLE

$$\begin{bmatrix}x'\\y'\end{bmatrix} = \begin{bmatrix}2\\2\end{bmatrix} +\begin{bmatrix}\cos (-90) & -\sin (-90) \\ \sin (-90) &\cos (-90)\end{bmatrix} \begin{bmatrix}1-2\\1-2\end{bmatrix}$$ $$\implies \begin{bmatrix}x'\\y'\end{bmatrix} = \begin{bmatrix}2\\2\end{bmatrix} +\begin{bmatrix}0 & 1 \\ -1& 0\end{bmatrix} \begin{bmatrix}-1\\-1\end{bmatrix} = \begin{bmatrix}1 \\ 3\end{bmatrix}$$

Hence the point (1,1) becomes (1,3) which fits as the above diagram