Question: I have a gameboard grid which is 20 rows high and 10 columns wide with the origin (0,0) being in the top left hand corner.
I have a tetrimino in play, which is composed of four blocks.
I have the x,y location of each block relative to the top left hand corner origin.
I also have the position of the pivot, the point around which I wish to rotate which is relative to the top left hand corner origin.

Each block has an integer position in a gameboard square and thus the pivot has a fractional position inbetween blocks e.g (10.5,10.5)

My question is: Which formula can I use to rotate each block around the pivot?

I have already looked at existing similar questions and answers but could not find an answer that I could get to work.

Help would be much appreciated.

Answer: 
General formula for rotating around origin is

```
xNew = x * cos(a) - y * sin(a)
yNew = x * sin(a) + y * cos(a)

```

For 90 degrees it becomes

```
xNew = -y
yNew = x

```

So, firstly get brick center coordinates relatively to pivot point:

```
x = xBrickCenter - xPivot
y = yBrickCenter - yPivot

```

Then rotate them around pivot point:

```
x1 = -y = yPivot - yBrickCenter
y1 = x = xBrickCenter - xPivot

```

And then add pivot coordinates to rotated point:

```
newXBrickCenter = xPivot + x1 = xPivot + yPivot - yBrickCenter
newYBrickCenter = yPivot + y1 = yPivot - xPivot + xBrickCenter

```

But if you need to rotate by multiples of 90 degrees, you can store four sets of brick positions for each orientation and switch between them instead of actually rotating.
You could rotate all square rings (a-through-h by 2 positions, A-through-P by 4 positions, and so on) around that pivot block:

```

ABCDE    MNOPA
PabcF    LghaB
Oh.dG -> Kf.bC
NgfeH    JedcD
MLKJI    IHGFE

```