Cross product as matrix multiplication

Visual Interactive Simulation, TDBD24, Spring 2006
Lecture 6
Outline
• Cross product as matrix multiplication
• The collision matrix
• The Newton Coulomb impulse for rigid bodies
• N‐C updates of translational and rotational velocities
• Multiple contact points
• An iterative solver (for lab 3‐4)
•Next lecture... • Intersection of convex polyhedra
• Separating axis theorem
• Intersection points for oriented bounding boxes (OBB)
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
Cross product as matrix multiplication
The cross product is defined as,
¯
¯ i
¯
a × b = ¯¯ ai
¯ bi
a = (ai , aj , ak ) , b = (bi , bj , bk )
¯
j k ¯¯
aj ak ¯¯ = (aj bk − bj ak , ak bi − bk ai , ai bj − bi aj )
bj bk ¯
Assume we could write this as a matrix product instead,
a× b = a × b
The special construct, the cross product matrix, a× , that allows this is,
⎛
⎞
0
−az ay
0
−ax ⎠
a× = ⎝ az
−ay ax
0
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
1
The collision matrix
The collision matrix is mainly a way to compactify notation.
An impulse will change the center of mass velocities as,
v´A,B = vA,B +/‐ J/mA,B
It will also change the angular velocities,
ω’A,B = ωA,B +/‐ I‐1A,B(rA,B x J) The new velocities at the collision points thus are,
u’A,B = uA,B +/‐ (J/mA,B + (I‐1A,B(rA,B x J)) x rA,B )
= uA,B +/‐ (1/mA,B ‐ rA,Bx I‐1A,B rA,Bx ) J
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
The collision matrix
Thus, the change in the relative collision velocity is,
∆u = u’ – u = (u’A – u’B ) – (uB – uA )
∆u = (1/mA + 1/mA ‐ (rAx I‐1A rAx + rBx I‐1B rBx) ) J
which can be written as,
∆u = K J
where K is called the collision matrix.
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
2
Newton Coulomb impulses for rigid bodies
First we assume sticking, with zero tangential velocity after the impact, that is,
u’t = 0
u’n = ‐e un
Given that ∆u = u’ – u, we can write the impulse as,
J = K‐1 (u’ – u)
We can compute normal and tangential components of J
Jn = (J⋅ n) n
Jt = J – Jn
The tangential friction is reactive and depends on the normal force. Sticking requires that,
| Jt| ≤ | Jn|
Otherwise we must consider sliding friction.
(identical with the ”max(...)” clamping law in previous lectures – look it up and compare!).
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
Newton Coulomb impulses for rigid bodies
For sliding, we first determine the direction of sliding,
ut = u – un
un = (u ⋅ n) n
Now we can compute the sliding unit vector,
t = ut / |ut|
Next, we define the sliding impulse to be,
(i.e. Jn = j n)
J = j n – µ j t
0 ≤ µ ≤ 1 is the friction coefficient.
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
3
Newton Coulomb impulses for rigid bodies
Thus, we know
• an expression for the impulse
• how this impulse changes the collision velocity
• how the normal velocity changes due to Newton’s impact law
Take the dot product of ∆u = u’ – u = K J with the collision normal n,
u’n = un + nT K J
Use Newton’s impact law u’n = ‐e un
‐ e un = un + nT K J
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
Newton Coulomb impulses for rigid bodies
Rearrange and insert the expression for J,
‐ (1+e)un = nT K(jn – µ j t)
Finally we solve for j, to compute the unknown impulse.
‐ (1+e)un = nT K(n – µ t) j
j = ‐ (1+e)un / nT K(n – µ t)
Knowing j, we can compute the impulse, and
Thus the new post‐collision translational and rotational velocities of body A and B, respectively!
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
4
Review – NC Rigid Body Collisions
• (Broad phase collision detection)
• Narrow phase collision detection
– List of intersections
•
•
•
•
Compute collision velocity
Check if colliding, resting or separating
If colliding, compute the NC impulse
Update translational (CoM) and rotational velocity
... add external forces, handle contacts, time integrate, render...
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
Multiple simultaneous contacts/collisions
E.g. Rigid body stacking.
J0 impulse
•
N bodies ‐ Solve using 2‐body interaction
–
–
–
•
•
We need something that works at the speed of sound, i.e. ~ 1000 m/s
If 1 body ~ 0.1 m, then we must propagate 10000 bodies/s or ~ 167 bodies/timestep –
thus a 167‐body method!!
•
Trend: An approximate solver solves just about this!
15 ms
15 ms
Frequency/wavelength limitation 15 ms
An impulse travels at 1 body/timestep ‐ that is 1 body/15 ms
It takes M timesteps to travel through M bodies ‐ Spooongy!
15 ms
15 ms
–
15 ms
15 ms
More brutal approximations enable stacks of up to thousands of bodies to be simulated in real‐time. Typically these use an iterative methods that boils down to Gauss‐Seidel.
15 ms
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
5
Bottom up iterative impulse solver
Basic idea:
• During each timestep loop through the collision set and solve collisions pair‐wise, and ”hope” that for each pass/iteration, there will be fewer and/or smaller collisions, until they are eventually all resolved...
• Treat collisions and contacts in a similar way (i.e. compute an impulse)
• Each iteration will propagate impulses one body through the system (i.e. we would need ~167 iterations in previous example).
Many tricks (and problems):
• How to choose the order of when you loop through the collision set?!
• How to avoid cycles (i.e. non‐convergence)?!
A top down method?
• Can be formulated from a matrix/algebraic formulation of the rigid body problem – i.e. the algorithm can actually be derived and better understood, whereas it is more like ”invented” in this bottom‐up approach.
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
Bridson, Guendelman, Fedkiw method
Guendelman, E., Bridson, R. and Fedkiw, R., ʺNonconvex Rigid Bodies with Stackingʺ, SIGGRAPH 2003, ACM TOG 22, 871‐878 (2003).
http://graphics.stanford.edu/papers/rigid_bodies‐sig03/
Follow‐ups:
Weinstein, R., Teran, J. and Fedkiw, R., ʺDynamic Simulation of Articulated Rigid Bodies with Contact and Collisionʺ, IEEE TVCG, (in press).
http://graphics.stanford.edu/~rachellw/prestabilization.html
D. M. Kaufman, T. Edmunds, and D. K. Pai, ``Fast Frictional Dynamics for Rigid Bodiesʹʹ in Proceedings of ACM SIGGRAPH 2005, Aug 2005. http://www.research.rutgers.edu/~kaufman/ffdfrb.html
Very much inspired by previous work by, Hahn, Steward, Mirtich and many others. See text book for more references.
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
6
Bridson, Guendelman, Fedkiw method
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
Bridson, Guendelman, Fedkiw method
• Uses Newton‐Coulomb impulses.
• Separates collisions from contacts and treats them separately in a cleaver way!
• In it’s simplest version – reuses original collision set throughout the timeset.
• Uses ”shock‐propagation” and a pre‐determined direction (gravity) to avoid loops and minimize errors.
• Ends with a position correction method that attempts to remove overlaps that still exist after the approximate solver has delivered.
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
7
Bridson, Guendelman, Fedkiw method
Algorithm:
1.
Find intersections
2.
Flag non‐separating intersections
3.
Collision loop over non‐separating intersections
i.
ii.
iii.
4.
Loop sequentially over rigid body pairs, and their non‐separating points, resolving the collisions, by instantaneously updating translational and angular velocity, and linear and angular momentum.
After each full pass through the non‐separating set, remove all points that now are separations.
Repeat N times (N= ~ 5‐15)
Add external forces, i.e. gravity, air friction, and time integrate the linear and angular momentum, linear and angular velocities. Do not update positions yet!
From the previous iteration, there may still be un‐resolved collisions that must be resolved. In addition teh velocity integration (e.g. gravity) will have introduced new collisions. Thus, flag all non‐separating contacts in the original contact set. These will now all be treated as resting contacts.
Collision loop over non‐separating intersections – to put them to rest
5.
6.
i.
ii.
7.
8.
Loop over bodies, and their non‐separating contacts to compute NC impulses and new velocities. Each pass through all non‐separating contacts is one iteration.
Start with a negative restitution e = ‐1 and for each iteration gradually take it down to 0 (e.g. ‐0.8 ‐0.6 ‐0.4 ‐0.2 0.0 for 5 iterations). Thus we will slowly damp the collision and finally put it to rest (provided the algorithm actually converges. Use N ~ 10‐20 iterations.
Use our new velocities and time integrate for new positions.
Check the original contact set (from 2). If these are still overlapping, then do a position correction loop on these contact pairs:
i.
ii.
Sometimes called ”first order physics”. Instead of computing an impulse, simply loop through the contact pairs, and separate them along the normal so that the penetration depth becomes zero. Let the separation be inversly proportional to the mass of the body, so that lighter bodies are moved further than heavy bodies (i.e. a fixed plane doesn’t move at all).
Since contact‐pair are dependent, repeat also this process with an iterative loop. In the first step only separate a fraction of the penetration depth, in the second, separate more, etc. So that the last iteration attempts to do a complete separation. Use ~5‐10 iterations.
April 3, 2006
TDB24 Spring 2006 -- Kenneth Bodin, Umeå University
8