嗨我有一个函数应该旋转一个2d向量,它保存来自pgm文件的像素值。顺时针旋转2d向量90度
void pgm_cw(vector <IVec> &p)
{
vector <IVec> temp; // temporary vector of vectors of ints
int count = 0; // count variable
int count2 = 0; // 2nd count variable
temp.resize(p.size());
for(count = 0; count < p.size(); count++)
{
temp[count].resize(p[count].size());
for(count2 = 0; count2 < temp[count].size(); count2++)
{
temp[count][count2] = p[count][count2];
}
}
for(count = 0; count < temp.size(); count++)
{
for(count2 = 0; count2 < temp[count].size(); count2++)
{
temp[count][count2] = temp[count][temp[count].size()-count2-1];
// set temp vector to p with 90 degree rotation
}
}
p = temp; // set p equal to temp
}
输出不正确。任何想法如何解决它?谢谢
在未来的问题,你可能需要准备[MCVE(http://stackoverflow.com/help/mcve),不包含类,如'IVec'需要猜测。另外,对于不起作用的简短程序,您可能希望在程序的各个阶段添加打印输出,指出他们正在做什么。 –