Archived

This topic is now archived and is closed to further replies.

Filip

matrices

Recommended Posts

Does anyone have an idea how to rotate a matrix(2d array in respect with c++).I have an 2d char array filled with various caharcters,letters and other.I need to rotate it 90 degrees to right.So i figured i would do this: void rot() { for(int a=0;aLink

Share this post


Link to post
Share on other sites
Your 2D matrix must be of quadratic size, like 10x10 or 20x20, orelse you''ll need more complex code to make up for the losses.


char data[64] // 8x8 array

char destination[64] // 8x8 destination array, we don''t wanna screw up the source data


// For each row

for (int y=0; y<8; y++) {

// For each column

for (int x=0; x<8; x++) {

// "Rotate"

destination[y*8+x] = data[x*8+(7-y)];
}
}


I know this is not mathematicly done, but if you want to do things fast, cheat :-)

(I hope I did it right

Albert

Share this post


Link to post
Share on other sites