Constrained r igid body simula tioncsci520/slides/ConstrRigid.pdf · Constrained r igid body simula...
Transcript of Constrained r igid body simula tioncsci520/slides/ConstrRigid.pdf · Constrained r igid body simula...
Constrained rigid body
simulation
constraints
Detect collision
Compute velocity change for colliding contact
Compute contact forces when rigid bodies are in resting contact
Collision detection
Determine when the collision occurs within a numerical tolerance
Determine all pairs of bounding boxes that overlap
Further check contact points between rigid bodies defined as convex polyhedra
Bisection
Y(t0)
Y(t0 + !t)
Y(t0 +1
2!t)
Y(tc)!
Bounding boxes
Use bounding boxes to reduce the number of pairwise collision/contact determinations
If two bounding boxes have no overlap, no further comparisons are needed
Determining all pairs of boxes that overlap can be done in time O(nlogd-2n+k) for d-dimensional bounding boxes
Coherence can substantially improve the performance
Bounding boxes
Each bounding box i can be described as an interval (bi, ei)
Find all pairs of interval that intersect
All the bi and ei are sorted from lowest to highest in a list
Maintain an active list which is initially empty
Whenever bi is encountered, all intervals on the active list are output as overlapping with i, and i is added to the list
Bounding boxes
Sweep and sort algorithm
I1
I2
I3 I4
I5 I6
b3 b5 b1 e5 e1 b6 b2 e3 b4 e6 e4 e2
Bounding boxes
We only need to do a full sort and sweep initially
What is the cost of the sorting process?
Subsequent comparisons can be improved by utilizing coherence
What is best sorting algorithm for a nearly sorted list?
Convex polyhedra
Two polyhedra do not inter-penetrate if and only if a
separating plane between them exists
Separating plane
Convex polyhedra
Separating plane
Check all possible edges or faces to find a separating plane at the very first time step of simulation or the first time two rigid bodies become close enough to require more than a bounding box test
Convex polyhedra
Defining face
Utilize coherence by caching defining faces or defining
edges
Y(t0)
Defining face
Y(t0 + !t)
Convex polyhedra
Defining face Defining face
The defining face no longer separate the polyhedra and a new separating plane must be found
If no separating plane is found, an inter-penetration has occurred at some earlier time
The simulator must back up until the collision time is determined
Contact points
Once we determine which bodies contact, we also need to determine the exact contact points
We consider two types of contacts
vertex/faces
edge/edge
Contact points
4 vertex/face 2 vertex/face
2 edge/edge
Contact points
A
B
A
Bnn
pa(t)
pb(t)
Although pa(t) and pb(t) are coincident at time tc, the
velocity of the two points may be different
pa(tc)
pb(tc)
Velocity of the contact point
vr = n(tc) · (pa(tc) ! pb(tc))
A
Bn
pa
pb
pb(tc) = vb(tc) + !b(tc) ! (pb(tc) " xb(tc))
pa(tc) = va(tc) + !a(tc) ! (pa(tc) " xa(tc))
This quantity gives the component of the relative velocity
in the normal direction
Velocity of the contact point
vr = 0vr > 0 vr < 0
A
B
pa(tc) ! pb(tc)
n
Separation
A
B
pa(tc) ! pb(tc)
n
Resting contact
A
B
pa(tc) ! pb(tc)
n
Colliding contact
Collision process
no force no force
∆t
Impulse:!
fdt = J = M!v
A soft collision
Force Velocity
∆t
A harder collision
Force Velocity
∆t
!t = 0
An infinitely hard collision
Force Velocity
fimp = ! fimp!t = J
Impulse and impulsive torque
In the rigid body world, we want velocity to chance
instantaneously
use impulse to change velocity instead of force
J = !P = M !v
If the impulse acts on a point p, then just as a force
produces a torque, J produces an impulsive torque
"imp = (p - x(t)) # J
impulsive torque gives rise to a change in angular momentum: "imp = !L = I(tc) $(tc)
Colliding contact
A
Bn
jn
When two bodies collide, we apply an impulse between them to change their velocity
For frictionless bodies, the direction of the impulse will be in the normal direction n(tc)
J = jn(tc)
Body A is subject to this impulse J, while body B is subject to an equal but opposite impulse -J
Colliding contact
A
Bn
A
Bn
p+a (tc) ! p
+
b(tc)p
!
a (tc) ! p!
b(tc)
jn
Relative velocity before and after the application of the impulse
To solve for j, we need one more piece of information
If we can solve for j, we then can compute the linear velocity of the rigid body after the collision
before
collision
after
collision
v!
r = n(tc) · (p!
a (t0) ! p!
b(t0))
v+r = n(tc) · (p
+a (t0) ! p
+b(t0))
The empirical law
Coefficient of restitution:
A
Bn
V!
r
! = 0
! = 1
! = 0.5! = 0
! = 1 Perfect bounce
Resting contact
v+r
= !!v!
r
compute the impulse
Now we are ready so solve for the impulse
Let’s first define the displacements from center of mass of the body
rb = pb(tc) ! xb(tc)ra = pa(tc) ! xa(tc) and
The pre-impulse velocity of pa:
The post-impulse velocity of pa: p+a
= v+a
(tc) + !+a
(tc) ! ra
p!
a= v
!
a(tc) + !
!
a(tc) ! ra
Replace with in v+a
(tc) v+a
(tc) = v!
a(tc) +
jn(tc)
Ma
p+a(tc)
!+a
(tc) = !!
a(tc) + I
!1(tc)(ra ! jn(tc))!+a
(tc)Replace with in p+a(tc)
compute the impulse
p+b(tc) = p!
b+ j
!
n(tc)
Mb
+ (I!1b
(tc)(rb ! n(tc))) ! rb
"
p+a(tc) = p!
a+ j
!
n(tc)
Ma
+ (I!1a
(tc)(ra ! n(tc))) ! ra
"
v+r = n(tc) · (p
+a (tc) ! p
+
b(tc))
n(tc) · (I!1
b(tc)(rb ! n(tc))) ! rb)
= n(tc) · (p!
a (tc) ! p!
b(tc)) + j(
1
Ma
+1
Mb
+ n(tc) · (I!1
a (tc)(ra " n(tc))) " ra+
= v!r +j(1
Ma
+1
Mb
+n(tc)·(I!1
a (tc)(ra!n(tc)))!ra+n(tc)·(I!1
b(tc)(rb!n(tc)))!rb)
v!r +j(1
Ma
+1
Mb
+n(tc)·(I!1
a (tc)(ra!n(tc)))!ra+n(tc)·(I!1
b(tc)(rb!n(tc)))!rb) = "!v!r
compute the impulse
j =!(1 + !)v!r
1
Ma+ 1
Mb+ n(tc) · (I
!1a (tc)(ra " n(tc))) " ra + n(tc) · (I
!1
b(tc)(rb " n(tc))) " rb)
Now we can compute the impulse and impulsive torque for body A and B
Finally, apply the change in linear momentum and angular momentum to the current state
L(tc + h) = L(tc) + !imp
P(tc + h) = P(tc) + J
J = jn(tc)!imp = ra ! J
A: B:!imp = rb ! J
J = !jn(tc)
Resting contact
In this case, all n contact points have the zero relative velocity
At each contact point there is some force , where fi is an unknown scalar
Our goal is to determine what each fi is and all the fi’s must be determined at the same time
fin(tc)
Resting contact
In the case of colliding contact, we established the relation between the velocity of the contact points and j, subject to the empirical law
For resting contact, we will establish the relation between acceleration of the contact points and fi’s subject to three conditions
Non-penetration
di(t) = ni(t) · (pa(t) ! pa(t))
A
Bn
pa(t)pb(t)
di(t) = 0
Bn
pb(t)
Apa(t)
di(t) < 0
A
Bn
pa(t) pb(t)
di(t) > 0
This is what wewant to avoid
Non-penetration
Since , we have to keep from decreasing; that is, we
have to keep
di(tc) = 0 di(tc)
di(tc) ! 0
di(t) = ˙ni(t) · (pa(t) ! pb(t)) + ni · (pa(t) ! pb(t))
At time tc, pa(tc) = pb(tc) This means that
The definition of two bodies in resting contact:
di(tc) = di(tc) = 0
di(tc) = vr
Non-penetration
Since describes the separation distance and describes the
separation velocity, measures how two bodies are accelerating
towards each other at the contact point
di(tc)di(tc)di(tc)
If ,the bodies have an acceleration towards each other and
the penetration will occur
di(tc) < 0
Therefore, the first condition is
di(tc) ! 0
Repulsive force
The contact forces can push bodies apart, but can never
act like “glue” and hold bodies together
Therefore, each contact force must act outward
fi ! 0
Workless force
The contact force at the a contact point becomes zero if
the bodies begin to separate
If contact is breaking , then fi should be zerodi(tc) > 0
If fi is not zero, then the contact is not breaking di(tc) = 0
What is the equation that satisfies these two cases?
fidi(tc) = 0
Resting contact conditions
A
Bn
f n
Condition 1: Non-penetration
Condition 2: Repulsive force
Condition 3: Workless force
di(t) = ni(t) · (pa(t) ! pb(t))
di(tc) ! 0
fi ! 0
where
fidi(tc) = 0
Compute contact forces
di(tc) = ai1f1 + ai2f2 + · · · + ainfn + bi
Step 1: compute A and b
!
"
#
d1(tc)...
dn(tc)
$
%
&
= A
!
"
#
f1
...fn
$
%
&
+ b
Step 2: solve f using quadratic programming
Compute contact forces
di(tc) = ni(tc) · (pa(tc) ! pb(tc)) + 2 ˙ni(tc) · (pa(tc) ! pb(tc))
Factor out the terms that depend on fj and assign them to
aij
Assign the rest of terms to bi
Quadratic programming
Solve for
Subject to
f1, f2, · · · , fn
fi ! 0
A
!
"
#
f1
.
.
.
fn
$
%
&
+ b ! 0
(ai1f1 + · · · + ainfn + bi)fi = 0
i = 1 · · ·n
i = 1 · · ·n
Summary
What’s the physical meaning of the rotation matrix?
How is the rotation matrix related to angular velocity?
How do you compute inertia tensor efficiently?
Why do we compute impulse instead of force in the case of colliding contact?
What’s next?
What are the equations of motion for articulated bodies?
How do we generalize constraints to articulated bodies?