how to rotate 90 2d array?

Jan 7, 2012 at 1:49pm
hey guys
i got an image that when u open it u see a matrix. and i need to rotatre the picture in 90 degrees.==>>> it means to rotate the matrix

now the thing is that i don't know how long is the row or the colon of the matrix, cause you can pick a size of a matrix and change it whenever u want.

i'll be more than happy if u guys can help with that thing..
Jan 7, 2012 at 1:55pm
How can you now know width and height of the matrix? What can you do with it without this?

To rotate a thing 90 degrees, x' = -y, y' = x. Surely you would want positive indices only, so it's x' = (height-1)-y.
If you want to rotate in the other direction, just move the minus from y to x.
Jan 7, 2012 at 2:42pm
thanks... i'll try it right now, and i c how it goes...!
Jan 7, 2012 at 3:47pm
<removed suggestion...>
Last edited on Jan 7, 2012 at 3:51pm
Jan 7, 2012 at 4:46pm
To do this you may need to know a little linear algebra. Specifically rotation matrices and matrix multiplication.

A 270 degrees (a 90 clockwise) rotation of a 2x2 matrix would look like the following:
1
2
|0 1| x |0  1| = |2 0|
|2 3|   |-1 0|   |3 1|


What you need to do is identify a rotational matrix for your case [nxm] and then use matrix multiplication to implement it.

a two degree rotation matrix is:
1
2
|0  1|
|-1 0|


A three degree (3x3) rotational matrix looks like:
1
2
3
| 1   0    0   |
| 0 cosQ -sinQ |
| 0 sinQ  cosQ |

or for the 270 degree case:
1
2
3
|1  0 0|
|0  0 1|
|0 -1 0|


You'll need to find a generic nxn or better nxm rotational matrix for 270 degrees (clockwise rotation).

You may want to start by looking here:
http://en.wikipedia.org/wiki/Rotation_matrix


Last edited on Jan 7, 2012 at 4:54pm
Topic archived. No new replies allowed.