<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Circle and Polygon Collision</title>
		<link>http://www.allegro.cc/forums/view/580534</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Thu, 20 Apr 2006 18:11:22 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>How would one go about checking collision between a circle and a polygon. More specifically a diamond shape? But I imagine there would be a generic algorithm for any polygon and a circle. 2 Rectangles I could do. 2 Circles I could do also, but mixing them I don&#39;t know how to start.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rick)</author>
		<pubDate>Thu, 20 Apr 2006 17:37:03 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Wouldn&#39;t it be easier to turn the circle into a polygon and then check for <a href="http://gpwiki.org/index.php/Polygon_Collision">collision between two polygons</a>?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (FMC)</author>
		<pubDate>Thu, 20 Apr 2006 17:49:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ll give it a try. Thanks.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Rick)</author>
		<pubDate>Thu, 20 Apr 2006 18:00:24 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Heh, sorry I just had to...</p><p>In OpenLayer:
</p><div class="source-code snippet"><div class="inner"><pre>Poly <a href="http://www.allegro.cc/manual/polygon" target="_blank"><span class="a">polygon</span></a><span class="k2">(</span> ... <span class="k2">)</span><span class="k2">;</span>
Circle <a href="http://www.allegro.cc/manual/circle" target="_blank"><span class="a">circle</span></a><span class="k2">(</span> pos, radius <span class="k2">)</span><span class="k2">;</span>

<span class="k1">if</span><span class="k2">(</span> polygon.Collides<span class="k2">(</span> Poly<span class="k2">(</span> circle.ToPolygon<span class="k2">(</span><span class="k2">)</span> <span class="k2">)</span><span class="k2">)</span><span class="k2">)</span> <span class="k2">{</span>
  <span class="c">// Collision!</span>
<span class="k2">}</span>
</pre></div></div><p>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Fladimir da Gorf)</author>
		<pubDate>Thu, 20 Apr 2006 18:00:37 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Wouldn&#39;t it be easier to turn the circle into a polygon and then check for collision between two polygons
</p></div></div><p>

That&#39;s not a good idea because firstly it would only be an approximation, and secondly it&#39;s a waste of resources.</p><p>You can do it properly by breaking the polygon up into line segments, and then calculating the perpendicular distance from the circle&#39;s centre to each line.  If the perpendicular distance is smaller than the radius of the circle and the perpendicular intersects the line segment, then you have a collision. Of course, you also have a collision if the distance from any of the points describing the polygon is closer to the centre of the circle than its radius.  Finally, for the case when the circle is completely inside the polygon, you&#39;ll need to check if the cenre of the circle is inside the polygon, which is your standard polygon-point intersection problem.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (james_lohr)</author>
		<pubDate>Thu, 20 Apr 2006 18:11:22 +0000</pubDate>
	</item>
</rss>
