I would like to do array manipulation like the following example.
Rotation 90 degree
a b
c d
becomes
c a
d b
Mathematically, just swap the x and y coordinate and put a - sign with x coordinate like 1,1--> -1,1.
But in terms of array, there is no negative index and starts from 0 so how can i deal with this operation?
Also the operation is accumulated like if i rotate it 4 times then the output is the same as the initial one.
Any hints or help would be appreciated.
"Swap x and y" is not "mathematically". Mathematically it is multiplication by rotation matrix. And I am not sure this helps you in rotating big rectangular matrix.
However for arrays things are simpler. Imagine array of size 100*100. Write down coordinates of its corner elements. Then write which coordinates these elements will have after rotation.
Umm.....i still cannot get what you mean
The corner x and y coordinate originally and after clockwise rotation are
0,0-->0,99
0,99-->99,99
up to this part, swapping and the y coordinate+99
99,99-->99,0
99,0-->0,0
but here swapping and the y coordinate -99
Also in the inner part like array[20][60], follow those equation will output a value which is over 99 or under 0
Can i do in this way?
1.swapping
2.x coordinate - 99
3.x coordinate* -1