A* 启发式创建 Bresenham 线

发布于 2024-11-03 03:23:48 字数 985 浏览 0 评论 0原文

根据我对 A* 启发式算法以及 Bresenham 算法工作原理的了解,这可能是不可能的,因为只有当前状态和目标状态会传递给启发式函数。但也许有人对这个问题有一个聪明的解决方案。

我正在使用 A* 在网格上规划一条路径,并且我想要一种启发式方法,当当前状态和目标之间存在自由空间或绕过障碍物的下一个转弯时,它会导致最佳路径遵循 Bresenham 线。

这是一些图片来说明问题。

曼哈顿距离

如果世界中的运动就像网格上的跳棋一样,那就完全没问题,但我最终会将 A* 路径转换为连续平面上的运动,所以这效果很好。

使用曼哈顿距离启发式从红色到绿色的最短路径

欧几里德距离:

更好,但仍然不完美。注意末端的直线。对角线可以很容易地保持对角线,这就是我想要的。

使用欧几里德距离启发式从红色到绿色的最短路径

我想要的:

Bresenham 线是抽到下一个回合或目标。

我真正想要的最佳路径,使用布雷森纳姆线到达目标

我在这里找到了一个很好的资源,http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html触及了我正在寻找的东西,但似乎只适用于绘制从起点到终点的布雷森纳姆线。我想要的是布雷森汉姆线也被吸引到绕过障碍物的下一个转弯。

对于解决这个问题的好方法有什么想法吗?

From what I understand about A* heuristics and how the Bresenham algorithm works, this may not be be possible since only the current state and goal state are passed to the heuristic function. But maybe someone has a clever solution to this problem.

I am using A* to plan a path on a grid, and I would like a heuristic that would cause the best path to follow a Bresenham's line when there are free spaces between the current state and the goal or the next turn around an obstacle.

Here are some images to illustrate the problem.

Manhattan distance:

If movements in the world acted like a checkers on a grid, this would be perfectly fine, but I'm eventually going to convert the A* path to motions on a continuously plane, so this does work very well.

The shortest path from red to green using the Manhattan distance heuristic

Euclidean distance:

Better, but still not perfect. Notice the straight line at the end. The diagonal could have just as easily remained a diagonal, which is what I want.

The shortest path from red to green using the Euclidian distance heuristic

What I Want:

Bresenham lines are draw to the next turn or goal.

The best path I actually want, which uses Bresenham lines to get to the goal

I found a good resource here, http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html that touches on what I am looking for, but only seems to work for drawing Bresenham lines from the start to the goal. What I want are Bresenham lines being draw to the next turn around an obstacle too.

Any ideas for a good approach to this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

随波逐流 2024-11-10 03:23:48

您能否即时修改成本函数,以便继续前进的成本随着累积误差而增加?

这个想法是,在算法开始时,像标准 Bresenham 一样计算 DX 和 DY。 (假设示例的其余部分 DX > DY > 0。针对其他方向进行相应修改。)

然后,对于每个访问的邻居节点,跟踪 Bresnaham 错误:

if (neighbor.X > this.X) 
   neighbor.err=this.err+DY 
else if (neighbor.Y > this.Y) 
   neighbor.err=this.err-DX

然后修改您的成本函数以支持增加 X,但添加 if (err >= DX/2) then cost=cost+FACTOR。在所有其他成本都相等的地图中,这应该追踪正确的线。

您可能需要的另一件事是当路径绕过障碍物时进行特殊处理,否则您可能会得到奇怪的沿着墙壁的路径,类似于链接文章中的“与障碍物的叉积”示例。只要邻居节点不在 +X 或 +Y 方向,您就可以通过重新计算 DX 和 DY 来处理这种情况。 (不幸的是,这可能需要跟踪每个节点的单独 DX、DY 和错误,这可能会产生太大的开销)

免责声明,我还没有实现 A* 或 Bresneham 算法年。这整个想法可能行不通

Can you modify the cost function on the fly so that the cost of going forward increases with the accumulated error?

The idea is, at the start of the algorithm, calculate DX and DY as in standard Bresenham. (Assume for the rest of the example that DX > DY > 0. Modify accordingly for other directions.)

Then for every visited neighbor node, track the Bresnaham error:

if (neighbor.X > this.X) 
   neighbor.err=this.err+DY 
else if (neighbor.Y > this.Y) 
   neighbor.err=this.err-DX

Then modify your cost function to favor increasing X, but add if (err >= DX/2) then cost=cost+FACTOR. In a map where all other costs are equal, this should trace the right line.

The other thing you might need is special handling when the path steps around an obstacle, otherwise you could get strange wall-following paths similar to the "cross-product with obatacles" example in your linked article. You could possibly handle that situation by recalculating DX and DY whenever the neighbor node is not in the +X or +Y direction. (Unfortunately, this likely requires tracking a separate DX, DY, and error for each node, which may be too much overhead)

Disclaimer, I haven't implemented an A* or Bresneham algorithm in years. This whole idea may be unworkable

妳是的陽光 2024-11-10 03:23:48

让所有的移动选择都是从当前位置可见的角点(或者目标,如果可见的话),一旦找到最短路径,在所有停靠点之间绘制布雷森汉姆线。

Have all your move alternatives be the corners visible from your current position (or the goal if it is visible), and once you find the shortest path, draw Bresenham lines between all your stops.

梦断已成空 2024-11-10 03:23:48

正如您链接到的文章的打破关系部分中所述,也许您可​​以在启发式中添加一个因素,即该节点位于其父节点和目标之间的线上的距离有多近。这样,如果可能的话,它会更愿意保持在直线路径上。

As described in the breaking ties section of the article you linked to, maybe you could add a factor to the heuristic that is how close does this node lie on a line between its parent and the goal. That way it would prefer staying on a straight line path when possible.

橙味迷妹 2024-11-10 03:23:48

您可以使用 Bresenham 算法(也许是自适应 Bresenham)进行碰撞检测,例如使用空间填充曲线吗?

Can you use a collision detection with the Bresenham algorithm, perhaps an adaptive Bresenham, for example with a space-filling-curve?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文