# Tetris: 2D Rotation Matrix?

I'm creating a Tetris clone right now. I've got the tiles of tetromino stored as an std::array<tile, 4>. Each tile holds its (x,y) coordinates relative to the piece. For example, the t-block is:

(-1, 0)
( 0, 0)
( 1, 0)
( 0,-1)


I want to create a function: rotate(const bool clockwise) that applies a 2D rotation matrix to the tiles to rotate the block either 90 degrees clockwise, or 90 degrees counter-clockwise.

After doing some reading on rotation matrixes, I've found that a 2D rotation matrix looks like this:

 cos(angle), sin(angle)
-sin(angle), cos(angle)


Since I'm doing 90 degrees only, I figure it should look like this:

//clockwise
0, 1
-1, 0

//counter-clockwise
0,-1
1, 0


After doing some more reading on how to multiply matrixes, multiplying the tile position by the matrix gives me this:

//(-1, 0) should end up as (0, 1) if rotated clockwise

-1                     0, 1                1,-1
0  /*multiplied by*/ -1, 0  /*gives me*/  0, 0


My question is how do I get an (x,y) position out of that result? Am I missunderstanding how matrixes work? Is there a more trivial way to rotate coordinates around the axis by 90 degrees?

• If you multiply a 2-element vector by a 2x2 matrix, you should get two elements (either in a row or in a column, depending on details). Oct 12 '15 at 1:19
• If you're doing a faithful clone, don't forget to apply the correct rotation rules: tetris.wikia.com/wiki/SRS Oct 12 '15 at 2:33

At 90 degrees, you can work out rotations in both directions just by swapping and reversing positions. Begin with the following shape:

Ahead, we rotate it manually clockwise, and look at the resulting positions (grey dots are rotated positions):

Analyzing point B's position: Before transforming, it was (1, 2). After transforming, it was (-2,1). If you look at the other points, they all follow the same pattern: Protated=(Py,-Px)

Applying the same principle you can find a similar property for counterclockwise 90-degree rotation: Protated=(-Py, Px)

And we never touched any matrices! However, note that this method rotates around the center (0,0)! So you should operate on the relative positions of the tiles, and not their world position (you would have to do that too with matrices, but it's always good to note).

# Reiterating:

• Clockwise: Protated=(Py,-Px)
• Counter-clockwise: Protated=(-Py, Px)