Rotate an image (specified by NxN
matrix) by 90 degrees
Consider
the following matrix:
If
rotation is done taking its center as a pivot point, then the
rotation will be like this:
So
basically, the matrix is divided into 4 parts by 2 diagonals.
To
complete the rotation, each part moves to its adjacent part’s
place.
If
we move one line to its adjacent line, then care needs to be taken
that the lines get progressively smaller as we move towards the
center.
Also,
the line gets smaller by 2 pixels, one from the start and one from
the end.
The
below code achieves the above target.
No
of lines (called layers below) to move in one part = N/2
