<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: QuadTree (Source Included)</title>
	<atom:link href="http://www.kyleschouviller.com/wsuxna/quadtree-source-included/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.kyleschouviller.com/wsuxna/quadtree-source-included/</link>
	<description></description>
	<pubDate>Wed, 07 Jan 2009 18:36:20 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
		<item>
		<title>By: Game Rendering &#187; Quadtree</title>
		<link>http://www.kyleschouviller.com/wsuxna/quadtree-source-included/#comment-1393</link>
		<dc:creator>Game Rendering &#187; Quadtree</dc:creator>
		<pubDate>Tue, 16 Dec 2008 19:31:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.kyleschouviller.com/index.php/quadtree-source-included/#comment-1393</guid>
		<description>[...] More info about quadtrees, including source: http://www.kyleschouviller.com/wsuxna/quadtree-source-included/ [...]</description>
		<content:encoded><![CDATA[<p>[...] More info about quadtrees, including source: <a href="http://www.kyleschouviller.com/wsuxna/quadtree-source-included/" rel="nofollow">http://www.kyleschouviller.com/wsuxna/quadtree-source-included/</a> [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle Schouviller</title>
		<link>http://www.kyleschouviller.com/wsuxna/quadtree-source-included/#comment-551</link>
		<dc:creator>Kyle Schouviller</dc:creator>
		<pubDate>Mon, 02 Jun 2008 01:12:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.kyleschouviller.com/index.php/quadtree-source-included/#comment-551</guid>
		<description>Yah, you can have the objects in any level of the tree - it's just best if they're in the leaf nodes, since you can eliminate the most collision checks if they are (in fact, the closer to the leaves the better).</description>
		<content:encoded><![CDATA[<p>Yah, you can have the objects in any level of the tree - it&#8217;s just best if they&#8217;re in the leaf nodes, since you can eliminate the most collision checks if they are (in fact, the closer to the leaves the better).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Josh</title>
		<link>http://www.kyleschouviller.com/wsuxna/quadtree-source-included/#comment-544</link>
		<dc:creator>Josh</dc:creator>
		<pubDate>Thu, 29 May 2008 03:29:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.kyleschouviller.com/index.php/quadtree-source-included/#comment-544</guid>
		<description>Hey Kyle!

Thanks for the excellent article with very readable code to boot!  I am curious about a few things at the moment...

I am planning to use a quad tree for collision detection and and considering pre-partitioning the tree as to not require many objects to be created during run-time.  That being said, would all objects have to be in leaf nodes of the tree for this to be feasible, or could the larger sized objects remain in higher level nodes, while smaller ones exist in leaf nodes?  I am not sure if the question actually makes sense, but it is something that I am trying to work through semantically at the moment.  Thanks again!

-Josh</description>
		<content:encoded><![CDATA[<p>Hey Kyle!</p>
<p>Thanks for the excellent article with very readable code to boot!  I am curious about a few things at the moment&#8230;</p>
<p>I am planning to use a quad tree for collision detection and and considering pre-partitioning the tree as to not require many objects to be created during run-time.  That being said, would all objects have to be in leaf nodes of the tree for this to be feasible, or could the larger sized objects remain in higher level nodes, while smaller ones exist in leaf nodes?  I am not sure if the question actually makes sense, but it is something that I am trying to work through semantically at the moment.  Thanks again!</p>
<p>-Josh</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle Schouviller</title>
		<link>http://www.kyleschouviller.com/wsuxna/quadtree-source-included/#comment-457</link>
		<dc:creator>Kyle Schouviller</dc:creator>
		<pubDate>Thu, 08 Nov 2007 00:53:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.kyleschouviller.com/index.php/quadtree-source-included/#comment-457</guid>
		<description>Todd:

Some sort of tree structure would probably work well, especially if things aren't moving a lot (meaning you can optimize the tree for querying).

You could also keep the objects in a list sorted on X, and then grab all objects between the left and right side of the viewport, and then prune out objects above the top or below the bottom of the viewport.  Whenever your viewport moved, you could add items in the new area (newViewport - oldViewport) to the visible list, and prune items from the list that aren't visible anymore.  That might be faster than a QuadTree for your purposes (Though some combination of the two methods might be even faster).</description>
		<content:encoded><![CDATA[<p>Todd:</p>
<p>Some sort of tree structure would probably work well, especially if things aren&#8217;t moving a lot (meaning you can optimize the tree for querying).</p>
<p>You could also keep the objects in a list sorted on X, and then grab all objects between the left and right side of the viewport, and then prune out objects above the top or below the bottom of the viewport.  Whenever your viewport moved, you could add items in the new area (newViewport - oldViewport) to the visible list, and prune items from the list that aren&#8217;t visible anymore.  That might be faster than a QuadTree for your purposes (Though some combination of the two methods might be even faster).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Todd Wilder</title>
		<link>http://www.kyleschouviller.com/wsuxna/quadtree-source-included/#comment-454</link>
		<dc:creator>Todd Wilder</dc:creator>
		<pubDate>Mon, 05 Nov 2007 15:09:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.kyleschouviller.com/index.php/quadtree-source-included/#comment-454</guid>
		<description>I've only seen quad tree examples for games and collision detection, i'm more of an application developer, and am developing an app with a large canvas (think huge excel document or 100 page word document), and need to virtualize the UI because the canvas is so big. Obviously i'll need some kind of function that, given the current viewport's location and size, will return all the objects that should be visible at this time. Would quad trees be a good fit for this application, or would other algorithms be more appropriate? The objects wouldn't move very often, but the four corners of the viewport would move A LOT.

Thanks!
Todd Wilder</description>
		<content:encoded><![CDATA[<p>I&#8217;ve only seen quad tree examples for games and collision detection, i&#8217;m more of an application developer, and am developing an app with a large canvas (think huge excel document or 100 page word document), and need to virtualize the UI because the canvas is so big. Obviously i&#8217;ll need some kind of function that, given the current viewport&#8217;s location and size, will return all the objects that should be visible at this time. Would quad trees be a good fit for this application, or would other algorithms be more appropriate? The objects wouldn&#8217;t move very often, but the four corners of the viewport would move A LOT.</p>
<p>Thanks!<br />
Todd Wilder</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle Schouviller</title>
		<link>http://www.kyleschouviller.com/wsuxna/quadtree-source-included/#comment-435</link>
		<dc:creator>Kyle Schouviller</dc:creator>
		<pubDate>Wed, 24 Oct 2007 04:23:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.kyleschouviller.com/index.php/quadtree-source-included/#comment-435</guid>
		<description>Mike:

1) Basically, when an object is on a boundary, it will be returned as if it were in the level above (e.g. a box on a boundary of two level-2 areas will be returned for the encompassing level 1 area above it).  In this case, it may be that when querying for an object in the bottom-right box, you get some object that's on the top-middle, since it's on the level above it.  A pretty simple IsNear check can help you cull those, though.

2) Well, lets see.  If you mean you'll have to find all objects in all nodes every time and move them around, then no.  If you set up a two-way relationship, objects can notify the tree-node they're in when they need to be moved, and that tree node can communicate with its parent and children to help move the object.  You're switching data around a lot, yes, but if you program it cleverly, it shouldn't be a huge issue (my example is programmed for understanding, not best practices!)

If you're talking about the tree being restructured and items moving around a lot, then yes, and this is the biggest problem with quadtrees (at least with mine!).  The QuadTree is constantly updating its structure as objects move through it, creating lots of nodes that will most of the time be empty (i.e. wasted space).  If you don't remove nodes (or remove them only after they've been stale for a while - like garbage collecting) you won't have as much of a problem with QuadTree nodes.  However, dynamic data structures can be a mess on the Xbox, because of the garbage collection, so if you're implementing a QuadTree for the Xbox, I suggest you:
a) Use structs for anything that's going to change a lot, since they don't allocate on the heap.
b) Use arrays instead of lists, so you don't have the problem of dynamic list garbage.
Basically, how you implement the QuadTree depends on your needs.  I mentioned in the comments here that you could also just pre-allocate the entire tree structure so you don't have the tree changing at all during execution.

So basically, there's no silver bullet for Quadtrees - you're going to have to make it suit your needs, and make sure you really need a Quadtree.</description>
		<content:encoded><![CDATA[<p>Mike:</p>
<p>1) Basically, when an object is on a boundary, it will be returned as if it were in the level above (e.g. a box on a boundary of two level-2 areas will be returned for the encompassing level 1 area above it).  In this case, it may be that when querying for an object in the bottom-right box, you get some object that&#8217;s on the top-middle, since it&#8217;s on the level above it.  A pretty simple IsNear check can help you cull those, though.</p>
<p>2) Well, lets see.  If you mean you&#8217;ll have to find all objects in all nodes every time and move them around, then no.  If you set up a two-way relationship, objects can notify the tree-node they&#8217;re in when they need to be moved, and that tree node can communicate with its parent and children to help move the object.  You&#8217;re switching data around a lot, yes, but if you program it cleverly, it shouldn&#8217;t be a huge issue (my example is programmed for understanding, not best practices!)</p>
<p>If you&#8217;re talking about the tree being restructured and items moving around a lot, then yes, and this is the biggest problem with quadtrees (at least with mine!).  The QuadTree is constantly updating its structure as objects move through it, creating lots of nodes that will most of the time be empty (i.e. wasted space).  If you don&#8217;t remove nodes (or remove them only after they&#8217;ve been stale for a while - like garbage collecting) you won&#8217;t have as much of a problem with QuadTree nodes.  However, dynamic data structures can be a mess on the Xbox, because of the garbage collection, so if you&#8217;re implementing a QuadTree for the Xbox, I suggest you:<br />
a) Use structs for anything that&#8217;s going to change a lot, since they don&#8217;t allocate on the heap.<br />
b) Use arrays instead of lists, so you don&#8217;t have the problem of dynamic list garbage.<br />
Basically, how you implement the QuadTree depends on your needs.  I mentioned in the comments here that you could also just pre-allocate the entire tree structure so you don&#8217;t have the tree changing at all during execution.</p>
<p>So basically, there&#8217;s no silver bullet for Quadtrees - you&#8217;re going to have to make it suit your needs, and make sure you really need a Quadtree.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mike V</title>
		<link>http://www.kyleschouviller.com/wsuxna/quadtree-source-included/#comment-433</link>
		<dc:creator>Mike V</dc:creator>
		<pubDate>Tue, 23 Oct 2007 09:55:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.kyleschouviller.com/index.php/quadtree-source-included/#comment-433</guid>
		<description>Thanks a lot for this article; it really gave me the boost I needed to finally start implementing a quad tree class.  Just a couple questions:

1) You said: "However, if there was an object on the middle line on the left (at level 1)".  I'm not sure which "middle line on the left" you're referring to.  Could you clarify this a bit?

2) Just to be clear, as object positions change, the quad tree will have to update their place in the tree, right?  If you have a ton of objects moving around (as in the hypothetical massively-multiplayer Pong game), wouldn't this cause a lot of churn inside the quad tree?  It seems as though the quad tree would become stale with every game update, and would essentially need to be re-examined every frame.  Is this true?</description>
		<content:encoded><![CDATA[<p>Thanks a lot for this article; it really gave me the boost I needed to finally start implementing a quad tree class.  Just a couple questions:</p>
<p>1) You said: &#8220;However, if there was an object on the middle line on the left (at level 1)&#8221;.  I&#8217;m not sure which &#8220;middle line on the left&#8221; you&#8217;re referring to.  Could you clarify this a bit?</p>
<p>2) Just to be clear, as object positions change, the quad tree will have to update their place in the tree, right?  If you have a ton of objects moving around (as in the hypothetical massively-multiplayer Pong game), wouldn&#8217;t this cause a lot of churn inside the quad tree?  It seems as though the quad tree would become stale with every game update, and would essentially need to be re-examined every frame.  Is this true?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Kyle Schouviller</title>
		<link>http://www.kyleschouviller.com/wsuxna/quadtree-source-included/#comment-223</link>
		<dc:creator>Kyle Schouviller</dc:creator>
		<pubDate>Mon, 10 Sep 2007 09:54:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.kyleschouviller.com/index.php/quadtree-source-included/#comment-223</guid>
		<description>Tom:

Sorry I didn't respond earlier - I've been busying myself so much and haven't looked at my website lately!

As to your question: you're most likely experiencing an issue with allocating nodes in the tree...especially if you're moving that many things around at once, and ESPECIALLY if you're running this on the Xbox.  While a Quadtree can handle that many objects, mine isn't optimized enough to do so gracefully.

The easy method would be to pre-divide all Quadtree nodes so you don't have to allocate anything while inserting / moving items (for any real-life situation I'd actually recommend this) - but you still end up with really deep leaves, which can take time to traverse, especially in the event that you resize your world (since my Quadtree uses a very naive resizing algorithm where it just rebuilds the whole thing).

Alternatively, you can increase the leaf size, so you can put more items in a node before it divides.  You still end up with the same problem though.

I'd suggest making markers at every 100 objects or so and see how the Quadtree is dividing.  Quadtrees handle distributed data really well - but when objects clump up is when Quadtrees have problems...especially on object boundaries.

I dunno - I'd need to know more about what you're doing to really help you come up with a better solution.</description>
		<content:encoded><![CDATA[<p>Tom:</p>
<p>Sorry I didn&#8217;t respond earlier - I&#8217;ve been busying myself so much and haven&#8217;t looked at my website lately!</p>
<p>As to your question: you&#8217;re most likely experiencing an issue with allocating nodes in the tree&#8230;especially if you&#8217;re moving that many things around at once, and ESPECIALLY if you&#8217;re running this on the Xbox.  While a Quadtree can handle that many objects, mine isn&#8217;t optimized enough to do so gracefully.</p>
<p>The easy method would be to pre-divide all Quadtree nodes so you don&#8217;t have to allocate anything while inserting / moving items (for any real-life situation I&#8217;d actually recommend this) - but you still end up with really deep leaves, which can take time to traverse, especially in the event that you resize your world (since my Quadtree uses a very naive resizing algorithm where it just rebuilds the whole thing).</p>
<p>Alternatively, you can increase the leaf size, so you can put more items in a node before it divides.  You still end up with the same problem though.</p>
<p>I&#8217;d suggest making markers at every 100 objects or so and see how the Quadtree is dividing.  Quadtrees handle distributed data really well - but when objects clump up is when Quadtrees have problems&#8230;especially on object boundaries.</p>
<p>I dunno - I&#8217;d need to know more about what you&#8217;re doing to really help you come up with a better solution.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom</title>
		<link>http://www.kyleschouviller.com/wsuxna/quadtree-source-included/#comment-179</link>
		<dc:creator>Tom</dc:creator>
		<pubDate>Thu, 30 Aug 2007 23:29:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.kyleschouviller.com/index.php/quadtree-source-included/#comment-179</guid>
		<description>Hello,

I want to thank you for the explaination of the quadtrees - it helped me out very much. I still have a performance question:
I want to add about 3000 objects to the tree and it gets stuck, it seems to do nothing anymore, could there be an error? I thought it would be no problem to handle this amount of objects (=parents, right?).
Well, I think it is a problem that many nodes get pushed down  during time and this is costly. Is there a good way to optimize this?

Thanks in advance,
Bye, Tom</description>
		<content:encoded><![CDATA[<p>Hello,</p>
<p>I want to thank you for the explaination of the quadtrees - it helped me out very much. I still have a performance question:<br />
I want to add about 3000 objects to the tree and it gets stuck, it seems to do nothing anymore, could there be an error? I thought it would be no problem to handle this amount of objects (=parents, right?).<br />
Well, I think it is a problem that many nodes get pushed down  during time and this is costly. Is there a good way to optimize this?</p>
<p>Thanks in advance,<br />
Bye, Tom</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hdd</title>
		<link>http://www.kyleschouviller.com/wsuxna/quadtree-source-included/#comment-92</link>
		<dc:creator>hdd</dc:creator>
		<pubDate>Mon, 25 Jun 2007 15:40:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.kyleschouviller.com/index.php/quadtree-source-included/#comment-92</guid>
		<description>sorry, similary chars was deleted...

			Random _rand = new Random(DateTime.Now.Second);
			QuadTree&#60;string&#62; m_qt = new QuadTree&#60;string&#62;(new Point(100, 100), 500);

			//populate quadtree
			for (int i= 0; i &#60; 500; i++)
			{
				m_qt.Insert(new QuadTreePositionItem&#60;string&#62;(Guid.NewGuid().ToString(),
				                                             new Point(_rand.Next(0, 100), _rand.Next(0, 100)),
				                                             new Point(10, 10)));
			}

			List&#60;QuadTreePositionItem&#60;string&#62;&#62; _resultList = new List&#60;QuadTreePositionItem&#60;string&#62;&#62;();
			Point _point;

			//get rectangle for 20 randomly generated points
			for (int i= 0; i &#60; 20; i++)
			{
				_point = new Point(_rand.Next(0, 100), _rand.Next(0, 100));

				m_qt.GetItems(_point, ref _resultList);

				Trace.WriteLine("-----------------------");
				Trace.WriteLine("Point: " + _point);

				foreach (QuadTreePositionItem&#60;string&#62; item in _resultList)
				{
					Trace.WriteLine("rect: " + item.Position);
				}
			}</description>
		<content:encoded><![CDATA[<p>sorry, similary chars was deleted&#8230;</p>
<p>			Random _rand = new Random(DateTime.Now.Second);<br />
			QuadTree&lt;string&gt; m_qt = new QuadTree&lt;string&gt;(new Point(100, 100), 500);</p>
<p>			//populate quadtree<br />
			for (int i= 0; i &lt; 500; i++)<br />
			{<br />
				m_qt.Insert(new QuadTreePositionItem&lt;string&gt;(Guid.NewGuid().ToString(),<br />
				                                             new Point(_rand.Next(0, 100), _rand.Next(0, 100)),<br />
				                                             new Point(10, 10)));<br />
			}</p>
<p>			List&lt;QuadTreePositionItem&lt;string&gt;&gt; _resultList = new List&lt;QuadTreePositionItem&lt;string&gt;&gt;();<br />
			Point _point;</p>
<p>			//get rectangle for 20 randomly generated points<br />
			for (int i= 0; i &lt; 20; i++)<br />
			{<br />
				_point = new Point(_rand.Next(0, 100), _rand.Next(0, 100));</p>
<p>				m_qt.GetItems(_point, ref _resultList);</p>
<p>				Trace.WriteLine(&#8221;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;&#8221;);<br />
				Trace.WriteLine(&#8221;Point: &#8221; + _point);</p>
<p>				foreach (QuadTreePositionItem&lt;string&gt; item in _resultList)<br />
				{<br />
					Trace.WriteLine(&#8221;rect: &#8221; + item.Position);<br />
				}<br />
			}</p>
]]></content:encoded>
	</item>
</channel>
</rss>
