1. 程式人生 > >BSP 樹 和 八叉樹

BSP 樹 和 八叉樹

八叉樹:

The Quadtree

derives  from the idea of dividing a square area into smaller squares.

start with a unity square as the root of the tree, now divide the square into four smaller aquares.

each of the new smaller squares is a child node of the root.  the next step is to repeat the process on the small suares

generating four more sub-squares and hence four children at the next level of the tree for each of them

imageimage

The Octree

in three dimensions the square is replaced by a cube and the division into four is replaced by a division into eight sub-cubes hence oct-tree,

Thus the octree is just a generalisation of the quadtree to 3D. Each node corresponds to a single cube and has exactly eight sub-nodes

imageimage

BSP樹

bsp_tree(poly* current_poly){

   while(still_polygons){

      partition_polygons(current_poly);

    }

bsp_tree(current_poly->left);

bsp_tree(current_poly->right);

}

image

應用

1. 查詢

image

2.可視判斷

image

3. 區域

image