搜题
问题   更新时间2023/4/3 12:59:00

补齐下述Bresenham算法。
if(delatRow < 0) stepRow = -1;else stepRow = 1;

if(delatCol < 0) stepCol = -1;else stepCol = 1;

delatRow = abs(delatRow *2);

delatCol = abs(delatCol *2);

currentStep = 0;

pathRow [currentStep] = nextRow;

pathCol [currentStep] = nextCol;

currentStep ++ ;

。。。

正确答案为: if (deltaCol > deltaRow) { fraction = (deltaRow * 2 – deltaCol)/2; while (nextCol != endCol) { if (fraction >= 0) { nextRow = nextRow + stepRow; fraction = fraction - deltaCol; } nextCol = nextCol + stepCol; fraction = fraction + deltaRow; pathRow[currentStep] = nextRow; pathCol[currentStep] = nextCol; currentStep++; } } else { fraction = (deltaCol * 2 – deltaRow)/2; while (nextRow != endRow) { if (fraction >= 0) { nextCol = nextCol + stepCol; fraction = fraction - deltaRow; } nextRow = nextRow + stepRow; fraction = fraction + deltaCol; pathRow[currentStep] = nextRow; pathCol[currentStep] = nextCol; currentStep++; } }
王老师:19139051760(拨打)