We are supposed to be writing a function that rotates a PGM file clockwise 90 degrees, passing a multidimensional vector through the function by reference. I'm not exactly sure how to go about doing this. The PGM files are not square matrices. I've tried swapping, but no such luck. I've erased all my code for it because it was too messy and became to hard to read.
Tip: If you can't be bothered to figure out the math one way, try to figure it out another way.
Intention: Try thinking of the R,C positions as Y,X and then rotate them 90 degrees with trig (sin, cos). Even though it's certainly not simple, it may be easier to understand (it is for me XD)
You could express it as a char vector instead, you would probably be better off creating a small class for this instead. I find it easier and a bit more efficient than having a vector within another vector.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
void rotateCW(std::vector<unsignedchar*> vec, int len)
{
std::vector<unsignedchar*> nvec;
for(int i = 0; i < len; i++)
{
nvec.push_back( newunsignedchar[vec.size()] );
}
for(int i = 0; i < len; i++){
for(int j = 0; j < vec.size(); j++){
nvec[i][j] = vec[j][i];
}
}
// would return nvec here or something, a container class would be better though~
}
I'd assume this would work if you have a multi dimensional vector instead, it isn't that hard really.