<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>minimum area bounding box</title>
		<link>http://www.allegro.cc/forums/view/590969</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Fri, 13 Apr 2007 04:05:59 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Anyone know of a good C/C++ algorithm for calculating the minimum area bounding box for any type of solid?  For example if you have a solid shape made of any number of vertices how would you calculate a rectangle around the shape with a minimum amount of area?  I can get the min/max of all the vertices but it only gives you rough box, not rotated in any way such that it touches the maximum amount of vertices and minimizes the extra area.</p><p>[edit]<br />I&#39;ll post a pic as soon as I figure out where my upload link went...<br />[/edit]
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Steve Terry)</author>
		<pubDate>Thu, 12 Apr 2007 06:25:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /> I&#39;m extremely new to collision detection. In fact the only way I know how to do collision detection is tile-based or hard-coded. Anyway, I&#39;m a little confused as to why you would want a rectangular bounding-box to be rotated on any angle...</p><p><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>If your detecting it based on a rectangle wouldn&#39;t you just use a flush rectangle? In other words, the maximum and minimum x&#39;s and y&#39;s...? <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Thu, 12 Apr 2007 06:29:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Here is what I want:<br /><span class="remote-thumbnail"><span class="json">{"name":"img","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/a\/fa0f69e588a33c9f536dadb352d16b0d.png","w":292,"h":269,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/f\/a\/fa0f69e588a33c9f536dadb352d16b0d"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/f/a/fa0f69e588a33c9f536dadb352d16b0d-240.jpg" alt="img" width="240" height="221" /></span></p><p>This shows two methods of bounding boxes on an odd shaped object.  There are many reasons to do the minimum area, one is collision detection like you mentioned.  The box is not precalculated so I will have to calculate it on the fly.  I don&#39;t want bounding spheres or bounding elipses, but boxes.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Steve Terry)</author>
		<pubDate>Thu, 12 Apr 2007 06:33:06 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Steve Terry said:</div><div class="quote"><p>
The box is not precalculated so I will have to calculate it on the fly.
</p></div></div><p>

Wouldn&#39;t it be more efficient to calculate only when the shape changes and store the bounding box? <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p><img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" /> Sorry, Steve, this doesn&#39;t help you much.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Thu, 12 Apr 2007 06:35:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I would like to know the algorithm before I can calculate it <img src="http://www.allegro.cc/forums/smileys/tongue.gif" alt=":P" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Steve Terry)</author>
		<pubDate>Thu, 12 Apr 2007 06:40:54 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Is there even a valid way to do that? I&#39;d imagine that any method would be hugely intensive since it&#39;d need to check the various angles of boxes and determine which produces the &quot;smallest&quot; box. I&#39;d either go with AABB (Axis-Aligned Bounding Box, as in your first example), or build the bounding box with your shape in an upright position, and just rotate it with the object.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Kitty Cat)</author>
		<pubDate>Thu, 12 Apr 2007 06:42:13 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>A single equation.. no!</p><p>But i can see how to do an iterative solution. Start out with an approximation (such as standard rectangle). Calculate the energy function.. in this case the area. Now you want to find a function that minimizes the area. Now it becomes a standard optimization problem. Might take some work to do a gradient descent but its probably a correct approach. Maybe define area( shape, boxAngle ). </p><p>sorry if that&#39;s a little obtuse.. but when dealing with hammers soo much everything looks like a nail. </p><p>Computationally that is not very efficient. You should probably pre-calculate it!
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Goalie Ca)</author>
		<pubDate>Thu, 12 Apr 2007 06:43:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Watch Numb3rs on Friday nights (or record it for later) and hope they eventually tell you the solution!</p><p>Is a bounding box even the best solution for collision detection? I would assume when you get into weird shapes there must be a better, more complex way...</p><p><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Thu, 12 Apr 2007 06:51:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;m not looking for speed here and if it helps any I do have the axis angle calculated so I know the angle the box will be at, just don&#39;t know how to shrink it down.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Steve Terry)</author>
		<pubDate>Thu, 12 Apr 2007 06:53:20 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Steve Terry said:</div><div class="quote"><p>
I&#39;m not looking for speed here and if it helps any I do have the axis angle calculated so I know the angle the box will be at, just don&#39;t know how to shrink it down.
</p></div></div><p>

The only way I can think of is guesses... Make a guess and check if you are too far. If you are, move back by half the distance you moved last time and check again. If you&#39;re not, move forward again.</p><p><img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /></p><p>Besides, how can you know what angle the box will be at for an oddly shaped object?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Thu, 12 Apr 2007 06:56:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you are looking for an algorithm that will do that from scratch, google gives this as the first result:</p><p><a href="http://valis.cs.uiuc.edu/~sariel/research/papers/00/diameter/diam_prog.html">link</a></p><p>Otherwise, if you know the axis of the box, what&#39;s preventing you from rotating the set of points in such a way as to make this axis be, say, vertical and then simply using the standard min/max algorithm to find the box? When you obtain the box you can  rotate the box corners back into the original orientation as needed.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (SiegeLord)</author>
		<pubDate>Thu, 12 Apr 2007 07:16:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I don&#39;t really know what I&#39;m talking about, but it seems to me that trying to find such a rectangle by approximations would take a lot of time, which I don&#39;t think is too god for any kind of game...</p><p>What I can think of doing is: take the standard rectangle bounding box of your example and divide it in smaller rectangles, maybe 32x32. Generate a pixel perfect collision detection mask for each of the rectangles, discard those that are all 0. This might take more time than a mathematical approximation, I don&#39;t know, but you would get a pixel perfect mask of the shape.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rampage)</author>
		<pubDate>Thu, 12 Apr 2007 07:49:38 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>If you say you know the angle then that&#39;s an easy one. Take a side, say the top, and move it in until that line intersects an edge. The check another side..
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Goalie Ca)</author>
		<pubDate>Thu, 12 Apr 2007 07:56:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">SiegeLord said:</div><div class="quote"><p>
Otherwise, if you know the axis of the box, what&#39;s preventing you from rotating the set of points in such a way as to make this axis be, say, vertical and then simply using the standard min/max algorithm to find the box? When you obtain the box you can rotate the box corners back into the original orientation as needed.
</p></div></div><p>

That sounds like a great idea. Yes, I think I&#39;ll take credit for that one. <img src="http://www.allegro.cc/forums/smileys/wink.gif" alt=";)" /><img src="http://www.allegro.cc/forums/smileys/cool.gif" alt="8-)" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Thu, 12 Apr 2007 08:08:07 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Seems like you should just calculate the slope of all of the pairs of vertices and create lines using them. Discard any lines that intersect with any other edges on the shape, of course. Take the line closest to the center of mass of the shape, then use that to find the next three edges.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Thu, 12 Apr 2007 09:53:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I was hoping this was a bounding box check thread <img src="http://www.allegro.cc/forums/smileys/sad.gif" alt=":(" />, I like answering that question.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Thu, 12 Apr 2007 22:41:09 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I think CGames has the right idea.  Draw a line from each vertice to all other vertices, discarding any lines that enter the shape.  This reduces your shape as follows:</p><p><span class="remote-thumbnail"><span class="json">{"name":"591890","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/7\/97a2347d189310d24347d33dc5ffbe82.jpg","w":254,"h":150,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/7\/97a2347d189310d24347d33dc5ffbe82"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/9/7/97a2347d189310d24347d33dc5ffbe82-240.jpg" alt="591890" width="240" height="141" /></span></p><p>This new image will be much easier to find the minimum area bounding box (I would assume).
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Onewing)</author>
		<pubDate>Thu, 12 Apr 2007 23:44:34 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
discarding any lines that enter the shape
</p></div></div><p>
I think you would need to find the <i>quickest path</i> around the shape without entering it.  I can find a few routes that don&#39;t enter the shape and aren&#39;t your resulting polygon.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (ImLeftFooted)</author>
		<pubDate>Fri, 13 Apr 2007 00:08:18 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Stupid GIMP can&#39;t draw lies, so I booted Windows and I&#39;m doing this from MS Paint.</p><p> <span class="remote-thumbnail"><span class="json">{"name":"591891","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/7\/579ae9e12f7c48259f01e1ee34e5cd46.png","w":345,"h":453,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/7\/579ae9e12f7c48259f01e1ee34e5cd46"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/5/7/579ae9e12f7c48259f01e1ee34e5cd46-240.jpg" alt="591891" width="240" height="315" /></span></p><p>1. Find all the lines between all the vertices. Discard those that intersect the polygon. The valid lines are shown in blue, some of the invalid ones are shown in red.</p><p>2. Find the shortest distance of each of the valid lines to the center of the shape. The shortest is shown in green, the rest in yellow.</p><p>3. From the point that the line come closest to the center of the shape (where the green line hits the blue on in step 2), find the first perpendicular line to the left and right that doesn&#39;t intersect with the shape.</p><p>3 b. Find the first parallel line down that doesn&#39;t intersect with the shape.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (CGamesPlay)</author>
		<pubDate>Fri, 13 Apr 2007 00:22:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>CGames... why Paint!? Paint sucks at drawing lines too! (esp at changing them)</p><p>What you want is <a href="http://inkscape.org/">inkscape</a>. It does vector drawing.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Goalie Ca)</author>
		<pubDate>Fri, 13 Apr 2007 01:23:43 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Stupid Gimp <i>can</i> draw lines. Click on start point. Shift-click on next points (vertices). Works with pencil, paintbrush, airbrush etc.</p><p>I would rotate my polygon in both directions and see what happens with the bounding rectangle. Compare rotate +epsilon degrees and -epsilon degrees and see in which direction you want to rotate to make the rectangle smaller. Then some kind of binary search for the minim.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Fri, 13 Apr 2007 03:08:28 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>
If you are using vector objects, wouldn&#39;t it be easier just to check if the vector objects overlap directly?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Richard Phipps)</author>
		<pubDate>Fri, 13 Apr 2007 03:35:49 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p><b>If...</b>
</p><div class="quote_container"><div class="title">Steve Terry said:</div><div class="quote"><p>
...I know the angle the box will be at...
</p></div></div><p>

<b>Then it makes sense to me to...</b>
</p><div class="quote_container"><div class="title">SiegeLord said:</div><div class="quote"><p>
...if you know the axis of the box, what&#39;s preventing you from rotating the set of points in such a way as to make this axis be, say, vertical and then simply using the standard min/max algorithm to find the box? When you obtain the box you can rotate the box corners back into the original orientation as needed.
</p></div></div><p>

<b>As in...</b></p><p> <span class="remote-thumbnail"><span class="json">{"name":"591899","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/d\/6d4b18ffc221daeddbf5789624d05009.jpg","w":543,"h":513,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/6\/d\/6d4b18ffc221daeddbf5789624d05009"}</span><img src="http://www.allegro.cc//djungxnpq2nug.cloudfront.net/image/cache/6/d/6d4b18ffc221daeddbf5789624d05009-240.jpg" alt="591899" width="240" height="226" /></span></p><p><i>(Pretend the objects are the same... MSPaint is rotationally challenged and I&#39;m no artist)</i></p><p><b>Otherwise, I&#39;m out of my league. ;D</b>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (bamccaig)</author>
		<pubDate>Fri, 13 Apr 2007 03:55:53 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>For some reason my vague memory is saying something about the covariance matrix and possibly eigenvectors. I&#39;m off to the &#39;net...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Thomas Harte)</author>
		<pubDate>Fri, 13 Apr 2007 04:05:59 +0000</pubDate>
	</item>
</rss>
