<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://wiki.darwinbots.com/index.php?action=history&amp;feed=atom&amp;title=Darwinbots3%2FPhysics%2FResponse</id>
		<title>Darwinbots3/Physics/Response - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://wiki.darwinbots.com/index.php?action=history&amp;feed=atom&amp;title=Darwinbots3%2FPhysics%2FResponse"/>
		<link rel="alternate" type="text/html" href="http://wiki.darwinbots.com/index.php?title=Darwinbots3/Physics/Response&amp;action=history"/>
		<updated>2026-04-07T19:12:50Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.29.0</generator>

	<entry>
		<id>http://wiki.darwinbots.com/index.php?title=Darwinbots3/Physics/Response&amp;diff=4915&amp;oldid=prev</id>
		<title>Numsgil: New page: This page covers the math behind collision response, especially in the case of multiple bodies forming a chain of direct and indirect collisions, such as a stack of bodies.  This is called...</title>
		<link rel="alternate" type="text/html" href="http://wiki.darwinbots.com/index.php?title=Darwinbots3/Physics/Response&amp;diff=4915&amp;oldid=prev"/>
				<updated>2009-05-16T09:53:56Z</updated>
		
		<summary type="html">&lt;p&gt;New page: This page covers the math behind collision response, especially in the case of multiple bodies forming a chain of direct and indirect collisions, such as a stack of bodies.  This is called...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;This page covers the math behind collision response, especially in the case of multiple bodies forming a chain of direct and indirect collisions, such as a stack of bodies.  This is called an '''island'''.&lt;br /&gt;
&lt;br /&gt;
== Basic concepts ==&lt;br /&gt;
&lt;br /&gt;
=== Forces' linear affects ===&lt;br /&gt;
Any force acting on a body, at any point on a body, applies the same change in acceleration to the body's center of mass.  Consider the diagram below:&lt;br /&gt;
 __________&lt;br /&gt;
 |        |&lt;br /&gt;
 |        |  &lt;br /&gt;
 |   X    |  &amp;lt;--- &amp;lt;math&amp;gt;\vec{Force_1}&amp;lt;/math&amp;gt;&lt;br /&gt;
 |        |&lt;br /&gt;
 |________|  &amp;lt;--- &amp;lt;math&amp;gt;\vec{Force_2}&amp;lt;/math&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
 ''' Diagram 1 '''&lt;br /&gt;
&lt;br /&gt;
Where X is the center of mass for the body.  &amp;lt;math&amp;gt;\vec{Force_1}&amp;lt;/math&amp;gt; is exactly centered, so it produces no torque.  The change in acceleration of the body's center of mass is given by &amp;lt;math&amp;gt;\Delta \vec{a} = \frac{\vec{Force_1}}{Mass}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt;\vec{Force_2}&amp;lt;/math&amp;gt; have the same magnitude and direction as &amp;lt;math&amp;gt;\vec{Force_1}&amp;lt;/math&amp;gt;.  However it's applying its force at a different point on the body, and will produce torque.  Even though it's off center, the change in acceleration for the body's center of mass is still &amp;lt;math&amp;gt;\Delta \vec{a} = \frac{\vec{Force_1}}{Mass}&amp;lt;/math&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
=== Forces' angular affects ===&lt;br /&gt;
Consider Diagram 1 again.  &amp;lt;math&amp;gt;\vec{Force_1}&amp;lt;/math&amp;gt; will not produce any change in angular acceleration for the body, because it is centered.  &amp;lt;math&amp;gt;\vec{Force_2}&amp;lt;/math&amp;gt; ''will'' produce change in angular acceleration, because it is off center.  In general, the '''torque''' (&amp;lt;math&amp;gt;\tau&amp;lt;/math&amp;gt;) produced by a force is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\tau = \vec{F} \cdot \vec{r_{\perp}^{P}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
And the change in angular acceleration is given by:&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\Delta \alpha = \frac{\tau}{I}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
* &amp;lt;math&amp;gt;\tau&amp;lt;/math&amp;gt; is the scalar torque term.&lt;br /&gt;
* &amp;lt;math&amp;gt;\vec{F}&amp;lt;/math&amp;gt; is the vector Force term.&lt;br /&gt;
* &amp;lt;math&amp;gt;\vec{r_{\perp}^{P}}&amp;lt;/math&amp;gt; is the vector perpendicular to the vector from the body's origin to the place &amp;lt;math&amp;gt;\vec{F}&amp;lt;/math&amp;gt; is acting on the body.&lt;br /&gt;
* &amp;lt;math&amp;gt;\alpha&amp;lt;/math&amp;gt; is the scalar angular acceleration&lt;br /&gt;
* &amp;lt;math&amp;gt;I&amp;lt;/math&amp;gt; is the body's scalar moment of inertertia.&lt;br /&gt;
&lt;br /&gt;
== Simple collision ==&lt;br /&gt;
&lt;br /&gt;
 __________      __&lt;br /&gt;
 |        |     /  |&lt;br /&gt;
 |        | ___/   |&lt;br /&gt;
 |   X    |P___  Y |&lt;br /&gt;
 |        |    \   |&lt;br /&gt;
 |________|     \__|&lt;br /&gt;
  &lt;br /&gt;
 ''' Diagram 2 '''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Consider a collision between two bodies: body X and body Y.  They collide at point P.  We assume that the collision takes 0 time.  That is, the bodies &amp;quot;instantly&amp;quot; resolve their collision.&lt;br /&gt;
&lt;br /&gt;
The change in angular and linear velocity for body X is given by:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;\Delta\vec{v} = \frac{j_0 \cdot \vec{n}}{m_X}&amp;lt;/math&amp;gt;&lt;br /&gt;
: &amp;lt;math&amp;gt;\Delta\omega = j_0 * \frac{\vec{r_{\perp}^{XP}} \cdot \vec{n}}{I_X}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where:&lt;br /&gt;
* &amp;lt;math&amp;gt;\Delta\vec{v}&amp;lt;/math&amp;gt; is the change in linear velocity.&lt;br /&gt;
* &amp;lt;math&amp;gt;\Delta\omega&amp;lt;/math&amp;gt; is the change in angular velocity.&lt;br /&gt;
* &amp;lt;math&amp;gt;j_0&amp;lt;/math&amp;gt; is the scalar impulse term applied to the body at point P to correct its velocity from the collision.&lt;br /&gt;
* &amp;lt;math&amp;gt;m_X&amp;lt;/math&amp;gt; is the scalar mass for the body.&lt;br /&gt;
* &amp;lt;math&amp;gt;I_X&amp;lt;/math&amp;gt; is the scalar moment of inertia for the body.&lt;br /&gt;
* &amp;lt;math&amp;gt;n&amp;lt;/math&amp;gt; is a vector representing the &amp;quot;normal&amp;quot; to the colision.  In the case of the vertex-on-edge collision in Diagram 2, n would probably be &amp;lt;math&amp;gt;&amp;lt;1, 0&amp;gt;&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt;\vec{r_{\perp}^{XP}}&amp;lt;/math&amp;gt; is the vector perpendicular to the vector from the center of mass of body X to the collision point P.&lt;br /&gt;
&lt;br /&gt;
Body Y likewise, but the changes are opposite in sign (equal and opposite reaction).&lt;br /&gt;
&lt;br /&gt;
We can define a relationship between the velocities before and after the collision using the [http://en.wikipedia.org/wiki/Coefficient_of_restitution coefficient of restitution].  Which is basically a fractional scalar value between 0 (for inelastic collisions) and 1 (for perfectly elastic collisions).&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;v_{XPf} - v_{YPf} = -(1 + \epsilon) * (v_{XPi} - v_{YPi})&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where:&lt;br /&gt;
* &amp;lt;math&amp;gt;v_{XPf}, v_{YPf}&amp;lt;/math&amp;gt; are the final velocities of bodies X and Y at point P.&lt;br /&gt;
* &amp;lt;math&amp;gt;\epsilon&amp;lt;/math&amp;gt; is the coefficient of restitution for the equation&lt;br /&gt;
* &amp;lt;math&amp;gt;v_{XPi}, v_{YPi}&amp;lt;/math&amp;gt; are the initial velocities of bodies X and Y at point P.&lt;br /&gt;
&lt;br /&gt;
To find the velocity of a body at a given point, use the formula:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;v_P = v + \omega * r^P_\perp&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where:&lt;br /&gt;
* &amp;lt;math&amp;gt;v_P&amp;lt;/math&amp;gt; is the velocity at a certain point on the body.&lt;br /&gt;
* &amp;lt;math&amp;gt;\omega&amp;lt;/math&amp;gt; is the body's angular velocity.&lt;br /&gt;
* &amp;lt;math&amp;gt;r^P_\perp&amp;lt;/math&amp;gt; is the vector perpindicular to the vector from the body's center of mass to point P.&lt;br /&gt;
&lt;br /&gt;
Using all of the equations above, we can find &amp;lt;math&amp;gt;j_0&amp;lt;/math&amp;gt; by the following algorithm:&lt;br /&gt;
&lt;br /&gt;
 suppose we are supplied with:&lt;br /&gt;
   a contact point '''P'''&lt;br /&gt;
   a collision normal '''n'''&lt;br /&gt;
   two bodies in collision, '''bodyX''' and '''bodyY'''&lt;br /&gt;
   a coefficient of restitution '''e'''&lt;br /&gt;
 &lt;br /&gt;
 Vector VelocityAtPoint(Body body, Vector point)&lt;br /&gt;
 {&lt;br /&gt;
   return body.Velocity + body.AngularVelocity * (point - body.Position);&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 Scalar ResistanceFromBody(Body body, Vector point, Vector n)&lt;br /&gt;
 {&lt;br /&gt;
   Vector rPerp = (point - body.Position).Perp();&lt;br /&gt;
   Scalar a = n.LengthSquared() * body.InverseMass; // The resistance to linear acceleration&lt;br /&gt;
   Scalar q = Squared(rPerp.DotProduct(n)) * body.InverseMomentOfInertia; // The resistance to angular acceleration&lt;br /&gt;
   &lt;br /&gt;
   return a + q;&lt;br /&gt;
 }&lt;br /&gt;
 &lt;br /&gt;
 Scalar vXP = VelocityAtPoint(bodyX, P);&lt;br /&gt;
 Scalar vYP = VelocityAtPoint(bodyY, P);&lt;br /&gt;
 &lt;br /&gt;
 Scalar b = -(1 + e) * (vXP - vYP).DotProduct(n);&lt;br /&gt;
 &lt;br /&gt;
 Vector rXPNorm = (point - bodyX.Position).Perp();&lt;br /&gt;
 Vector rYPNorm = (point - bodyY.Position).Perp();&lt;br /&gt;
 &lt;br /&gt;
 Scalar resistanceX = ResistanceFromBody(bodyX, P, n);&lt;br /&gt;
 Scalar resistanceY = -ResistanceFromBody(bodyY, P, n); //equal but opposite&lt;br /&gt;
 &lt;br /&gt;
 Scalar j0 = b / (resistanceX - resistanceY);&lt;br /&gt;
 &lt;br /&gt;
 return j0;&lt;br /&gt;
&lt;br /&gt;
== Multiple collisions ==&lt;br /&gt;
Consider the case of collisions between '''N''' bodies simultaneously.  We can expand from the last section to handle N contact points.  The change in linear and angular velocity of a body is described by the equation:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;\Delta\vec{v} = \Large{\frac{\sum_{i=0}^{N-1} j_i \cdot \vec{n}}{m}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;\Delta\omega = \Large{\frac{\sum_{i=0}^{N-1} j_i \cdot \vec{r_{\perp}^{Pi}} \cdot \vec{n}}{I}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
where:&lt;br /&gt;
* &amp;lt;math&amp;gt;j_i&amp;lt;/math&amp;gt; is 0 if that contact point isn't part of that body's collision.&lt;br /&gt;
&lt;br /&gt;
We can now form N equations (one for each collision), and solve for N unknowns (each collision impulse &amp;lt;math&amp;gt;j_i&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
The equation for collision &amp;lt;math&amp;gt;i&amp;lt;/math&amp;gt; is given by:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;\large{V_{BPi} + V_{APi} = b_i}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;\large{V_{XPi} = \sum_{k=0}^{k=N-1} (aX_k + qX_k)} \cdot j_k&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;\large{aX_k = \frac{\vec{n_i} \cdot \vec{n_k}}{m_X}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;\large{qX_k = \frac{ (\vec{r^{XPi}_\perp} \cdot \vec{n_i}) \cdot (\vec{r^{XPk}_\perp} \cdot \vec{n_k})}{I_X}}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;\large{b_i = -(1 + \epsilon) ((V_{BP} - V_{AP}) \cdot n_i)}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt;\large{V_{XP} = V_X + \omega_X \cdot r^{XP}_\perp}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
All terms in the above quantities are known at the beginning of the collision except for &amp;lt;math&amp;gt;j_i&amp;lt;/math&amp;gt;.  So we can represent the system of equation as:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
:&amp;lt;math&amp;gt;\large{\mathbf{A} \mathbf{j} = \mathbf{b} }&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For an example, suppose that there are 4 collisions.  One between body A and body B (collision 0), two between body B and body C (collision 1 and 2), and one between body C and body D (collision 3).  If we take the equation for &amp;lt;math&amp;gt;V_{XPi}&amp;lt;/math&amp;gt; above, are replace &amp;lt;math&amp;gt;j_k&amp;lt;/math&amp;gt; with commas, we can form the system of equations into a matrix:&lt;br /&gt;
&lt;br /&gt;
: &amp;lt;math&amp;gt; \large{&lt;br /&gt;
\begin{bmatrix}&lt;br /&gt;
V_{BP0} - V_{AP0} \\&lt;br /&gt;
V_{CP1} - V_{BP1} \\&lt;br /&gt;
V_{CP2} - V_{BP2} \\&lt;br /&gt;
V_{DP3} - V_{CP3} \\&lt;br /&gt;
\end{bmatrix} \begin{bmatrix}&lt;br /&gt;
j_0 \\&lt;br /&gt;
j_1 \\&lt;br /&gt;
j_2 \\&lt;br /&gt;
j_3 \\&lt;br /&gt;
\end{bmatrix} = \begin{bmatrix}&lt;br /&gt;
b_0 \\&lt;br /&gt;
b_1 \\&lt;br /&gt;
b_2 \\&lt;br /&gt;
b_3 \\&lt;br /&gt;
\end{bmatrix} }&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Which can then be solved in &amp;lt;math&amp;gt;O(N^3)&amp;lt;/math&amp;gt;.&lt;/div&gt;</summary>
		<author><name>Numsgil</name></author>	</entry>

	</feed>