Presentation is loading. Please wait.

Presentation is loading. Please wait.

Quadtrees 1.

Similar presentations


Presentation on theme: "Quadtrees 1."— Presentation transcript:

1 Quadtrees 1

2 Background Split along pre-defined planes Used to partition 2-D space
In general, a quadtree is a tree in which each node has at most 4 children Each node of the tree corresponds to a square region If a node has children, think of its region being chopped into 4 equal subregions. Child nodes correspond to these smaller subregions of their parent’s region Subdivide as little or as much as necessary Each internal node has exactly 4 children

3 Quadtree Example The root node of a quadtree corresponds to a square region in space. Generally, this encompasses the entire “region of interest”. If desired, subdivide along lines parallel to the coordinate axes, forming four smaller identically sized square regions. The child nodes correspond to these. Some or all of these children may be subdivided further. Octrees work in a similar fashion, but in 3-D, with cubical regions subdivided into 8 parts. A A A A B C B C D E D E A A B C B C D E D E F G F G H I H I

4 Collision Detection Two objects that are at opposite ends of the screen can not possibly collide, so there is no need to check for a collision between them. We can use quadtree to reduce the number of checks. A quadtree starts as a single node. Objects added to the quadtree are added to the single node.

5 Collision Detection When more objects are added to the quadtree, it will eventually split into four subnodes. Each object will then be put into one of these subnodes according to where it lies in the 2D space. Any object that cannot fully fit inside a node’s boundary will be placed in the parent node. Each subnode can continue subdividing as more objects are added

6 Collision Detection As you can see, each node only contains a few objects. We know then that, for instance, the objects in the top-left node cannot be colliding with the objects in the bottom-right node, so we don't need to run an expensive collision detection algorithm between such pairs.

7 Implementation of the Operations
Actual objects stored inside the leaves, not inner nodes. Insert an object into the quadtree Check if the object intersects the current node. If so, recurse. If you've reached the leaf level, insert the object into the collection. Delete an object from the quadtree Execute the exact same steps as if inserting the object, but when you've reached the leaf level delete it from the collection. Test if an object intersects any object inside the quadtree Execute the exact same steps as if inserting the object, but when you've reached the leaf level check for collision with all the objects in the collection. Test for all collisions between all objects inside the quadtree For every object in the quadtree execute the single object collision test. Update the quadtree Delete all objects from the quadtree whose position has been modified and insert them again.

8 ?

9 References


Download ppt "Quadtrees 1."

Similar presentations


Ads by Google