1

I am writing a program that needs a nxn array to be rotated about it's center. Rotations are only at 90-degree angles.

What I do is I translate the origin to the center and perform the rotation, then translate it back again.

For example,a 3x3 array:

0 0 1
0 1 1
0 1 1

when rotated 90 degrees about it's center, becomes:

1 1 1
0 1 1
0 0 0

using (1,1) as it's center, then after getting the positions relative to the center, applying the rotation transformation. The problem is when I have an even-numbered dimension, a 4x4 array for example:

0 1 1 1
1 1 1 0
0 0 0 0
0 1 0 0

What is it's center? Or rather, how do I correctly rotate the array using a transformation matrix?

Edit: assume that the arrays can contain anything, integers or maybe even objects

userx01
  • 273
  • 2
  • 13

0 Answers0