|
本题添加时间:2023/4/3 12:59:00 |
|
圆梦客服:王老师 19139051760(微信同号) 19139051760(微信同号) |
补齐下述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++;
}
}
出自
人工智能 学起plus弘成系统
石家庄铁道大学
|
更多试题>>>>
1、请写出分隔规则实现的代码
2、游戏领域会切割成不连续的砖块(正方形,或正六边形),玩家位置会固定在某个砖块上,不能同时跨越不同的砖格。
×
√
3、机器人学是研究在任何条件下都能够完成人类部分的行动或功能的机器
×
√
4、计算每一点与终点间的横轴和纵轴,比较二者的长度,往较长轴方向前进,若两轴等长,则沿对角线前进.
×
√
5、与或图中本原问题对应的节点称为终止节点
×
√
|