<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>The middle point from a set of points</title>
		<link>http://www.allegro.cc/forums/view/350025</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 14 Apr 2004 12:22:58 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>http://edu.kauhajoki.fi/~juipe/Stuff/probby.png</p><p>What I would like to know is that how to retrieve the middle point from a set of points. The set can be of any size from 3 to lots (cases with one and two points are trivial to solve), and the points in the set are not necessarily laid out in a symmetrical way. To make it slightly more fun, the points are not restricted to a 2D plane like in the examples - they are points in 3D space.</p><p>In the examples, the black points are the points of the set, and the red point is the middle point.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Inphernic)</author>
		<pubDate>Sat, 10 Apr 2004 14:11:51 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Loop through each point and find the smallest x/y/z values, and the biggest, then:
</p><div class="source-code snippet"><div class="inner"><pre><span class="k2">(</span><span class="k2">(</span>max_x <span class="k3">-</span> min_x<span class="k2">)</span> <span class="k3">/</span> <span class="n">2</span><span class="k2">)</span> <span class="k3">+</span> min_x<span class="k2">;</span>
<span class="k2">(</span><span class="k2">(</span>max_y <span class="k3">-</span> min_y<span class="k2">)</span> <span class="k3">/</span> <span class="n">2</span><span class="k2">)</span> <span class="k3">+</span> min_y<span class="k2">;</span>
<span class="k2">(</span><span class="k2">(</span>max_z <span class="k3">-</span> min_z<span class="k2">)</span> <span class="k3">/</span> <span class="n">2</span><span class="k2">)</span> <span class="k3">+</span> min_z<span class="k2">;</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Sat, 10 Apr 2004 14:50:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Works great, thanks for the fast reply!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Inphernic)</author>
		<pubDate>Sat, 10 Apr 2004 15:07:25 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;d say that if you calculate the average of all x,y,z coordinates you&#39;ll get better results, for example in a case like this:</p><div class="source-code snippet"><div class="inner"><pre>
 <span class="k3">*</span>
             <span class="k3">*</span>
          <span class="k3">*</span>


             <span class="k3">*</span>

              <span class="k3">*</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Sat, 10 Apr 2004 19:00:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If the point you&#39;re looking for must be in the original set, then you should average the coordinates of the points and look for the point with the shortest distance to that coordinate.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Bob)</author>
		<pubDate>Sat, 10 Apr 2004 20:47:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
Averaging will move the &quot;middle&quot; around if an unusually large number of points is to one side instead of the other ...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (23yrold3yrold)</author>
		<pubDate>Sat, 10 Apr 2004 20:49:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>The method should depend on how the set of points were created...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Plucky)</author>
		<pubDate>Sat, 10 Apr 2004 21:00:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>Averaging will move the &quot;middle&quot; around if an unusually large number of points is to one side instead of the other ...</p></div></div><p>
Depends what Inphernic means by middle I guess. If he means the point which, if you put any hyperplane through has more or less the same number of points on one side as the other then obviously this isn&#39;t a consideration.</p><p>If instead he means the middle as in the most central point, then he is explicitly thinking about bounding forms, so might want to do something like calculate full extent along every axis and find the midpoint of that (i.e. the midpoint of the axis aligned bounding box). Beyond that I guess he wants to project onto axes, and find the point where the surface integral to the left of a point is equal to that on the right?</p><p>EDIT: and don&#39;t forget:</p><p>((max_x - min_x) / 2) + min_x<br />= max_x/2 - min_x/2 + min_x<br />= max_x/2 + min_x/2<br />= (max_x + min_x)/2</p><p>Cuts out an incredible one addition - probably not even one cycle nowadays!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Sat, 10 Apr 2004 21:07:44 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>If instead he means the middle as in the most central point, then he is explicitly thinking about bounding forms</p></div></div><p>

That is what I wanted, but I can settle for a slightly simpler solution (which I should&#39;ve figured out - shame on me <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />). </p><p>For the curious, the original goal was to get a center point for camera to focus on if there are multiple objects in the field (so that by focusing on to that point, every object gets on the screen - of course, camera distance to that point had to be considered, but that is not a problem anymore).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Inphernic)</author>
		<pubDate>Sun, 11 Apr 2004 01:56:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>[url <a href="http://www2.inf.ethz.ch/personal/gaertner/miniball.html">http://www2.inf.ethz.ch/personal/gaertner/miniball.html</a>]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rash)</author>
		<pubDate>Sun, 11 Apr 2004 02:28:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>AFAIK, there is two ways depending on what you want.<br />If you want the center of a bounding box defined by the most extreme points in the set, you already have the answer in the thread.<br />Just do it dimension by dimension, you can have any nomber of dimensions, it doesn&#39;t matter.</p><p>Then there is the average point. Dimension by dimension sum all points and divide by the number of points.</p><p>The thing I&#39;d like to know is about optimisation.<br />How can this be done as fast as possible?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trezker)</author>
		<pubDate>Tue, 13 Apr 2004 14:39:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
How can this be done as fast as possible? 
</p></div></div><p>
with the min/max method is quite easy: keep somwhere these min/max and update them accordingly when you move/add/delete a point. Note: if you chage a lot of points every frame, thne this may get slower.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Oscar Giner)</author>
		<pubDate>Tue, 13 Apr 2004 17:54:41 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you are talking about having a situtation of being able to remove or add a single point from a large set after initial calculation:</p><p>The average version is probably easier, because the algorithm doesn&#39;t require branching if you want the average point, but for the bounding box method you will have to check if the point is a maximum or a minimum, and if so, find the new max or min (for each dimension).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gillius)</author>
		<pubDate>Wed, 14 Apr 2004 08:10:19 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How exactly do you define the &#39;middle point&#39;?</p><p>What if you have four points arranged to form a perfect square.  Which one is considered the middle?</p><p>Anyway, if the problem amouts to just finding the median of a list, it can be done in O(n) time.  There is a quick selection method that can select the n&#39;th element from any list by performing a series of partitions that is guarnteed to take no more than 10n or so operations.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (David Layne)</author>
		<pubDate>Wed, 14 Apr 2004 08:16:00 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>David: I think that he does not want the middle-most point of the set, but, rather, he wants to generate a new point which is in the &quot;middle&quot; of the set of existing points -- so for the case of a perfect square, it would just be the average position of them all the points in the set.  Overall, though, it&#39;s not clear what middle means, as was mentioned throughout this thread.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Zaphos)</author>
		<pubDate>Wed, 14 Apr 2004 11:43:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Once you&#39;ve got the initial max, min or total values you should keep them if you&#39;re going to change the set of points.<br />So when you add a point you just need to check it against the previous max, min or add it to the total, then calc the middle.<br />When removing, with the max/min method you&#39;d need to redo the search, with the average method you just need to reduce the total by that points value.<br />If you&#39;re changing the set alot each time you might want to do the final calculation separately after all adding/removal. Doing it for each change would be rather stupid in that case.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Trezker)</author>
		<pubDate>Wed, 14 Apr 2004 12:22:58 +0000</pubDate>
	</item>
</rss>
