傢伙,我有一個很奇怪的問題。我試圖實現一個嵌套的for循環其將一個矩形成更小的塊,然後進行檢查以查看這些更小的塊的具有點從i已經在他們定義的陣列(大矩形是320 * 240順便說一句):嵌套for循環遍歷不正確
int[,] edgetrunc = new int[edgeIndex, 2]; //edgeIndex is the number of points in the external array
Array.Copy(edgePoint, edgetrunc, edgeIndex*2);//truncates the nulls from the tail of my array
int delx = 16;//width of block
int dely = 12;//height of block
int blockIndex = new int();
bool[] block = new bool[(depthFrame.Width/delx)*(depthFrame.Height/dely)];
for (int ymin = 0;ymin < depthFrame.Height;ymin += dely)
{
for (int xmin = 0; xmin < depthFrame.Width; xmin += delx)
{
blockIndex = (xmin/delx) + (ymin/dely);
for (int i = 0; i < edgeIndex; i++)
{
if (edgetrunc[i, 0] >= xmin && edgetrunc[i, 0] < xmin++ && edgetrunc[i, 1] >= ymin && edgetrunc[i, 1] < ymin++)
{
block[blockIndex] = true;
break;
}
}
}
}
繼承人問題雖然,我把第二個for循環(xmin循環)的斷點,並開始迭代它,並在第一次迭代時xmin的值從0跳到320,然後停留在那裏和每個迭代都會改變ymin。我要去克雷?我做錯了什麼?
PS我甚至測試這一點,我得到了同樣的問題:
for (int ymin = 0;ymin < depthFrame.Height;ymin += dely)
{
for (int xmin = 0; xmin < depthFrame.Width; xmin += delx)
{
}
}
編輯:
想通了,很奇怪,apparantly它與我試圖找到方法來做到塊索引。爲了解決這個問題,我初始化blockIndex爲0以外的for循環,把blockIndex ++第三次for循環後,感謝您的幫助反正=)
int blockIndex = 0;
bool[] block = new bool[(depthFrame.Width/delx)*(depthFrame.Height/dely)];
for (int ymin = 0;ymin < depthFrame.Height;ymin += dely)
{
for (int xmin = 0; xmin < depthFrame.Width; xmin += delx)
{
for (int i = 0; i < edgeIndex; i++)
{
if ((edgetrunc[i, 0] >= xmin) && (edgetrunc[i, 0] < (xmin + delx)) && (edgetrunc[i, 1] >= ymin) && (edgetrunc[i, 1] < (ymin + dely)))
{
block[blockIndex] = true;
break;
}
}
blockIndex++;
}
}
,不幸的是沒有工作,請參閱我的問題的更新。 – 2012-02-07 06:36:33