Box2D树成本启发式

时间:2015-03-02 15:20:06

标签: algorithm box2d binary-tree

我在项目中使用Box 2D中的树。它是一个外部(面向叶子)的二叉树,每个节点都有一个轴对齐的边界框,父节点边界框​​是它的叶子框的并集。添加新节点时,算法沿着树向下,决定放置它的位置,计算成本。代码:

//current is the node on the current level, node is the node being added
currentPerimeter=current.box.perimeter;
combinedPerimeter=(current.box ∪ node.box).perimeter;
//the cost of adding the node to the current level
currentCost=2*combinedPerimeter;
//the cost of going down further
inheritanceCost=2*(combinedPerimeter-currentPerimeter);

//calculating the cost of adding the node to the left subtree
lCombinedRect=(node.box ∪ current.leftNode.box);
if(current.leftNode.isLeaf){
   leftCost=inheritanceCost+lCombinedRect.perimeter;
} else {
   leftCost=inheritanceCost+lCombinedRect.perimeter-current.leftNode.box.perimeter;
}
//the same code is for the right subtree

如果currentCost最低,则将节点添加到当前级别,否则将对右侧或左侧子级执行相同的操作。

问题是我不了解成本启发式。在第一次修订中,有一个表面区域启发式,但现在它是不同的。你能解释启发式的目的是什么,它最小化了什么参数?我还想修改树,将z-index间隔数据添加到树节点。那我该如何修改启发式呢?

0 个答案:

没有答案