<?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; physics</title>
	<atom:link href="http://wp.freya.no/tag/physics/feed/" rel="self" type="application/rss+xml" />
	<link>http://wp.freya.no</link>
	<description>Knowledge is power</description>
	<lastBuildDate>Wed, 28 Jul 2010 16:50:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Simple AABB vs AABB collision detection</title>
		<link>http://wp.freya.no/3d-math-and-physics/simple-aabb-vs-aabb-collision-detection/</link>
		<comments>http://wp.freya.no/3d-math-and-physics/simple-aabb-vs-aabb-collision-detection/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 21:13:02 +0000</pubDate>
		<dc:creator>kent</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AABB]]></category>
		<category><![CDATA[bounding box]]></category>
		<category><![CDATA[cpp]]></category>
		<category><![CDATA[physics]]></category>

		<guid isPermaLink="false">http://wp.freya.no/</guid>
		<description><![CDATA[An AABB is an axis aligned bounding box. It&#8217;s mainly used in broadphase physics detection. Assume this are the basic properties of an AABB. struct AABB { Point c; // center point float r[3]; // halfwidths }; Then we can use this simple test to check if there is an overlap between the bounding boxes. [...]]]></description>
			<content:encoded><![CDATA[<p>An AABB is an axis aligned bounding box. It&#8217;s mainly used in broadphase physics detection.</p>
<p>Assume this are the basic properties of an AABB.</p>
<pre class="brush: cpp;">
struct AABB
{
	Point c;		// center point
	float r[3];	// halfwidths
};
</pre>
<p>Then we can use this simple test to check if there is an overlap between the bounding boxes.</p>
<pre class="brush: cpp;">
bool testAABBAABB(const AABB &amp;a, const AABB &amp;b)
{
	float t;
	if ( Abs(a.c[0] - b.c[0]) &gt; (a.r[0] + b.r[0]) return false;
	if ( Abs(a.c[1] - b.c[1]) &gt; (a.r[1] + b.r[1]) return false;
	if ( Abs(a.c[2] - b.c[2]) &gt; (a.r[2] + b.r[2]) return false;
	// We have an overlap
	return true;
};
</pre>
 <img src="http://wp.freya.no/wp-content/plugins/feed-statistics.php?view=1&post_id=627" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://wp.freya.no/3d-math-and-physics/simple-aabb-vs-aabb-collision-detection/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<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 [...]]]></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/feed-statistics.php?view=1&post_id=49" width="1" height="1" style="display: none;" />]]></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>3</slash:comments>
		</item>
	</channel>
</rss>
