<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Freya.no &#187; collision detection</title>
	<atom:link href="http://wp.freya.no/tag/collision-detection/feed/" rel="self" type="application/rss+xml" />
	<link>http://wp.freya.no</link>
	<description>Knowledge is power</description>
	<lastBuildDate>Mon, 06 Feb 2012 19:56:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Simple Sphere-Sphere Collision Detection and Collision Response</title>
		<link>http://wp.freya.no/3d-math-and-physics/simple-sphere-sphere-collision-detection-and-collision-response/</link>
		<comments>http://wp.freya.no/3d-math-and-physics/simple-sphere-sphere-collision-detection-and-collision-response/#comments</comments>
		<pubDate>Sat, 13 Jan 2007 00:33:31 +0000</pubDate>
		<dc:creator>kent</dc:creator>
				<category><![CDATA[Dev]]></category>
		<category><![CDATA[Interessant]]></category>
		<category><![CDATA[Mathematics]]></category>
		<category><![CDATA[c++]]></category>
		<category><![CDATA[collision detection]]></category>
		<category><![CDATA[collision response]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[physics]]></category>
		<category><![CDATA[sample]]></category>

		<guid isPermaLink="false">http://wp.freya.no:8081/simple-sphere-sphere-collision-detection-and-collision-response/</guid>
		<description><![CDATA[Collision Detection To determine if two spheres are colliding, we take the sum of the radiuses and compare it with the length from the centers of the spheres. If the lenght is smaller than the sum of the radiuses, we have a collision. Difference vector (the length is the distance between those two spheres): Then [...]
No related posts.]]></description>
			<content:encoded><![CDATA[<h4>Collision Detection</h4>
<p>To determine if two spheres are colliding, we take the sum of the radiuses and compare it with the length from the centers of the spheres. If the lenght is smaller than the sum of the radiuses, we have a collision.</p>
<p>Difference vector (the length is the distance between those two spheres):<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_1ad4fecfcbffb16bf5374a5bd74ee47d.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{d} = s1.pos - s2.pos" title="vec{d} = s1.pos - s2.pos"/></p>
<p>Then the length is computed:<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_edce18b53884d387f286b8274e05fb5f.png" style="vertical-align:-6.5px; display: inline-block ;" alt="distance = vec{d}.length = sqrt{vec{d}.x^2 + vec{d}.y^2 + vec{d}.z^2}" title="distance = vec{d}.length = sqrt{vec{d}.x^2 + vec{d}.y^2 + vec{d}.z^2}"/></p>
<p>Sum of the radiuses:<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_0636561826ac95e5d00b58a58f3aca76.png" style="vertical-align:-6.5px; display: inline-block ;" alt="sumradius = s1.radius + s2.radius" title="sumradius = s1.radius + s2.radius"/></p>
<p>If distance&lt;sumradius the we have a collision to take care of.</p>
<h4>Collision Response</h4>
<p>This is the little more trickier part, but with some basics explained, it should be pretty straight forward.</p>
<p>First, find the vector which will serve as a basis vector (x-axis), in an arbiary direction. It have to be normalized to get realistic results.<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_ebd360c6605889a8139e404ef67b0136.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{x} = s1.pos - s2.pos" title="vec{x} = s1.pos - s2.pos"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_992.5_8bdda451a896c946571d5f23cf41b2ef.png" style="vertical-align:-7.5px; display: inline-block ;" alt="vec{x}.normalize()" title="vec{x}.normalize()"/></p>
<p>Then we calculate the x-direction velocity vector and the perpendicular y-vector.<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_11ec07179dadc6c6fe979f4619b239fb.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v1} = s1.vel" title="vec{v1} = s1.vel"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_978.5_349c47d18213b7a895a9909823302ed9.png" style="vertical-align:-21.5px; display: inline-block ;" alt="x1 = x.dot(vec{v1})" title="x1 = x.dot(vec{v1})"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_338d5e1941d266abb8c35093f09f0548.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v1x} = vec{x} * x1" title="vec{v1x} = vec{x} * x1"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_8a5b09bd06b4d142e3578eea62b121dd.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v1y} = vec{v1} - vec{v1x}" title="vec{v1y} = vec{v1} - vec{v1x}"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_293078dcca8e50c3566b72c90240d8ec.png" style="vertical-align:-6.5px; display: inline-block ;" alt="m1 = s1.mass" title="m1 = s1.mass"/></p>
<p>Same procedure for the other sphere.<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_df1d17eae325a0dbb1e60d9c0ec0441a.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{x} = vec{x}*-1" title="vec{x} = vec{x}*-1"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_24a3ea12480a0a0d9a2b9eac70d81719.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v2} = s2.vel" title="vec{v2} = s2.vel"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_978.5_a047e0b10c6be77b548ff3637566cf4b.png" style="vertical-align:-21.5px; display: inline-block ;" alt="x2 = vec{x}.dot(vec{v2})" title="x2 = vec{x}.dot(vec{v2})"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_2e88b35173b53531247925f1f0437b2d.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v2x} = vec{x} * x2" title="vec{v2x} = vec{x} * x2"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_a73913e9e491c7dd66c0a4cd328d3586.png" style="vertical-align:-6.5px; display: inline-block ;" alt="vec{v2y} = vec{v2} - vec{v2x}" title="vec{v2y} = vec{v2} - vec{v2x}"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_993.5_e9f38ad62dea050fa44d594c4cb2730b.png" style="vertical-align:-6.5px; display: inline-block ;" alt="m2 = s2.mass" title="m2 = s2.mass"/></p>
<p>Then we mix and play around with some of Newtons laws to obtain a formula for the speed (in vector format) after the collision.<br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_980_0406a44cd44e4bfaa605e04a12b53018.png" style="vertical-align:-20px; display: inline-block ;" alt="s1.vel = vec{v1x}{(m1-m2)/(m1+m2)} + vec{v2x}{(2*m2)/(m1+m2)} + vec{v1y}" title="s1.vel = vec{v1x}{(m1-m2)/(m1+m2)} + vec{v2x}{(2*m2)/(m1+m2)} + vec{v1y}"/><br />
<img src="http://wp.freya.no/wp-content/plugins/wpmathpub/phpmathpublisher/img/math_980_0df4aac98b257531dc85729d713b47e8.png" style="vertical-align:-20px; display: inline-block ;" alt="s2.vel = vec{v1x}{(2*m1)/(m1+m2)} + vec{v2x}{(m2-m1)/(m1+m2)} + vec{v2y}" title="s2.vel = vec{v1x}{(2*m1)/(m1+m2)} + vec{v2x}{(m2-m1)/(m1+m2)} + vec{v2y}"/></p>
<p>And it actually works! <img src='http://wp.freya.no/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h4>Sample application:</h4>
<p><a href="http://wp.freya.no/websvn/listing.php?repname=Public&amp;path=%2Fopengl%2Fcollisiondetect%2F">Source code in subversion repository</a>.</p>
<p><img class="alignnone" title="Collision detection sample" src="http://wp.freya.no/websvn/filedetails.php?repname=Public&amp;path=%2Fopengl%2Fcollisiondetect%2Fsample.jpg" alt="" width="656" height="518" /></p>
 <img src="http://wp.freya.no/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=49" width="1" height="1" style="display: none;" /><p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwp.freya.no%2F3d-math-and-physics%2Fsimple-sphere-sphere-collision-detection-and-collision-response%2F&amp;title=Simple%20Sphere-Sphere%20Collision%20Detection%20and%20Collision%20Response" id="wpa2a_6"><img src="http://wp.freya.no/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/3d-math-and-physics/simple-sphere-sphere-collision-detection-and-collision-response/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
	</channel>
</rss>

