关于A的findFValue函数里,我想把四个方向的拓展点变成八个方向的,即使规划的路径不仅限于上下左右,可以斜着走,加了后续四个方向后发现
case 'euclidean'
heuristic(1) = 10abs(goalpos(2)-newx) + 10abs(goalpos(1)-newy);
这一段有点不理解,欧式距离为什么会用到曼哈顿距离的公式,所以我自己换成了
heuristic(1) = 10norm(goalpos()-[newx,newy]);
然后代码就报错了,有时能正常运行但路径还是不能斜着走
代码如下,只需要在原有的四个方向上加上斜向的四个方向即可:
function [F] = findFValue(xEnd, yEnd, currentNodeX, currentNodeY,g)
% compute F value (F) = cost (g) + heuristic (h)
h = abs(xEnd - currentNodeX) + abs(yEnd - currentNodeY); % the Manhattan distance
g = g+1; % increasing g by 1 since it is one unit away from the current node
F = g+h;
其中的曼哈顿距离替换成了横纵坐标的绝对值之和。