Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with huge objects in a quad tree

Let's say I have circular objects. Each object has a diameter of 64 pixels.

The cells of my quad tree are let's say 96x96 pixels.

Everything will be fine and working well when I check collision from the cell a circle is residing in + all it's neighbor cells.

BUT what if I have one circle that has a diameter of 512 pixels? It would cover many cells and thus this would be a problem when checking only the neighbor cells. But I can't re-size my quad-tree-grid every time a much larger object is inserted into the tree...

like image 551
Napoleon Avatar asked Sep 16 '25 13:09

Napoleon


2 Answers

Instead och putting objects into a single cell put them in all cells they collide with. That way you can just test each cell individually. Use pointers to the object so you dont create copies. Also you only need to do this with leavenodes, so no need to combine data contained in higher nodes with lower ones.

like image 180
Bozemoto Avatar answered Sep 18 '25 08:09

Bozemoto


This an interesting problem. Maybe you can extend the node or the cell with a tree height information? If you have an object bigger then the smallest cell nest it with the tree height. That's what map's application like google or bing maps does.

Here a link to a similar solution: http://www.gamedev.net/topic/588426-2d-quadtree-collision---variety-in-size. I was confusing the screen with the quadtree. You can check collision with a simple recusion.

like image 34
Micromega Avatar answered Sep 18 '25 10:09

Micromega