modeling and solving constraintsbasic idea ⚫ constraints are used to simulate joints, contact, and...
TRANSCRIPT
![Page 1: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/1.jpg)
Modeling and Solving
Constraints
Erin Catto
Blizzard Entertainment
![Page 2: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/2.jpg)
Basic Idea
⚫ Constraints are used to simulate joints, contact,
and collision.
⚫ We need to solve the constraints to stack boxes
and to keep ragdoll limbs attached.
⚫ Constraint solvers do this by calculating impulse
or forces, and applying them to the constrained
bodies.
![Page 3: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/3.jpg)
Overview
⚫ Constraint Formulas
⚫ Jacobians, Lagrange Multipliers
⚫ Modeling Constraints
⚫ Joints, Motors, Contact
⚫ Building a Constraint Solver
⚫ Sequential Impulses
![Page 4: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/4.jpg)
Constraint Types
Contact and Friction
![Page 5: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/5.jpg)
Constraint Types
Ragdolls
![Page 6: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/6.jpg)
Constraint Types
Particles and Cloth
![Page 7: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/7.jpg)
Show Me the Demo!
![Page 8: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/8.jpg)
Bead on a 2D Rigid Wire
( , ) 0C x y =Implicit Curve Equation:
This is the position constraint.
![Page 9: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/9.jpg)
How does it move?
v
The normal vector is perpendicular to the velocity.
n
dot( , ) 0=n v
![Page 10: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/10.jpg)
Enter The Calculus
( ) 0C =x
Position Constraint:
0C =Velocity Constraint:
If C is zero, then its time derivative is zero.
x
y
=
x
![Page 11: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/11.jpg)
Velocity Constraint
⚫ Velocity constraints define the allowed motion.
⚫ Next we’ll show that velocity constraints depend
linearly on velocity.
0C =
![Page 12: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/12.jpg)
The Jacobian
Due to the chain rule the velocity constraint has
a special structure:
C = Jv
J is a row vector called the Jacobian.
J depends on position.
x
y
=
v
The velocity constraint is linear.
![Page 13: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/13.jpg)
The Jacobian
v
TJ
The Jacobian is perpendicular to the velocity.
0C = =Jv
![Page 14: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/14.jpg)
Constraint Force
v
Assume the wire is frictionless.
What is the force between the wire and the bead?
![Page 15: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/15.jpg)
Lagrange Multiplier
v
cF
Intuitively the constraint force Fc is parallel to
the normal vector.
T
c =F JDirection known.
Magnitude unknown.implies
![Page 16: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/16.jpg)
Lagrange Multiplier
⚫ The Lagrange Multiplier (lambda) is the constraint force
signed magnitude.
⚫ We use a constraint solver to compute lambda.
![Page 17: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/17.jpg)
Jacobian as a
CoordinateTransform
⚫ Similar to a rotation matrix.
⚫ Except it is missing a couple rows.
⚫ So it projects some dimensions to zero.
⚫ The transpose is missing some columns, so some
dimensions get added.
![Page 18: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/18.jpg)
Velocity Transform
v J C
Cartesian
Space
Velocity
Constraint
Space
Velocity
C = Jv
![Page 19: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/19.jpg)
Force Transform
cF
Constraint
Space
Force
Cartesian
Space
Force
TJ
T
c =F J
![Page 20: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/20.jpg)
Refresher: Work and Power
Work = Force times Distance
Work has units of Energy (Joules)
Power = Force times Velocity (Watts)
( )dot ,P = F V
![Page 21: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/21.jpg)
Principle of Virtual Work
T
c =F J
Principle: constraint forces do no work.
( ) 0T
T T
c cP = = = =F v J v Jv
Proof (compute the power):
The power is zero, so the constraint does no work.
We can ensure this by using:
![Page 22: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/22.jpg)
Constraint Quantities
C
C
J
Position Constraint
Velocity Constraint
Jacobian
Lagrange Multiplier
![Page 23: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/23.jpg)
Why all the Painful
Abstraction?
⚫ We want to put all constraints into a common form for the
solver.
⚫ This allows us to efficiently try different solution
techniques.
![Page 24: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/24.jpg)
Addendum:
Modeling Time Dependence
⚫ Some constraints, like motors, have prescribed motion.
⚫ This is represented by time dependence.
( ), 0C t =x
( ) 0C b t= + =Jv
Position:
Velocity:
velocity bias
![Page 25: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/25.jpg)
Example: Distance Constraint
T
C =x
vx
T
=x
Jx
y
x
L
C L= −x
0b =
Position:
Velocity:
Jacobian:
Velocity Bias: is the tension
particle
x
y
=
x
![Page 26: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/26.jpg)
Gory Details
( )
( )
( )
2 2
2 2
2 2
2 2
2 2
1
2
20
2
1
x y
T Tx
y
dC dx y L
dt dt
d dLx y
dt dtx y
xv yv
x y
vx
vyx y
= + −
= + −+
+= −
+
= =
+
xv
x
![Page 27: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/27.jpg)
Computing the Jacobian
⚫ At first, it is not easy to compute the Jacobian.
⚫ It gets easier with practice.
⚫ If you can define a position constraint, you can find its
Jacobian.
⚫ Here’s how …
![Page 28: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/28.jpg)
A Recipe for J
⚫ Use geometry to write C.
⚫ Differentiate C with respect to time.
⚫ Isolate v.
⚫ Identify J and b by inspection.
C b= +Jv
![Page 29: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/29.jpg)
Constraint Potpourri
⚫ Joints
⚫ Motors
⚫ Contact
⚫ Restitution
⚫ Friction
![Page 30: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/30.jpg)
Joint: Distance Constraint
T
c =F Jy
x
v
a m=F g
T
=x
Jx
![Page 31: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/31.jpg)
Motors
A motor is a constraint with limited force (torque).
sinC t= −
Example
10 10−
A Wheel
Note: this constraint does work.
![Page 32: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/32.jpg)
Velocity Only Motors
2C = −
Example
Usage: A wheel that spins at a constant rate.
We don’t care about the angle.
5 5−
![Page 33: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/33.jpg)
Inequality Constraints
⚫ So far we’ve looked at equality constraints (because they are simpler).
⚫ Inequality constraints are needed for contact and joint limits.
⚫ We put all inequality position constraints into this form:
( , ) 0C t x
![Page 34: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/34.jpg)
Inequality Constraints
0C
The corresponding velocity constraint:
If
0C Else
skip constraint
enforce:
![Page 35: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/35.jpg)
Inequality Constraints
Force Limits:
Inequality constraints don’t suck.
0
![Page 36: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/36.jpg)
Contact Constraint
⚫ Non-penetration.
⚫ Restitution: bounce
⚫ Friction: sliding, sticking, and rolling
![Page 37: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/37.jpg)
Non-Penetration Constraint
n
C =
p
body 2
body 1
(separation)
![Page 38: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/38.jpg)
Non-Penetration Constraint
( ) ( )
( )
( )
2 1
2 2 2 1 1 1
1
1 1
2
2 2
( )p p
T
C = −
= + − − − −
− − − =
−
v v n
v ω p x v ω p x n
n v
p x n ω
n v
p x n ω
J
( )
( )
( )
=
=
A B C
C A B
B C A
Handy Identities
![Page 39: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/39.jpg)
Restitution
2 1( )n p pv − v v n
Relative normal velocity
Adding bounce as a velocity bias
nb ev−=0n nC v ev+ −= +
n nv ev+ − −
Velocity Reflection
![Page 40: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/40.jpg)
Friction Constraint
Friction is like a velocity-only motor.
The target velocity is zero.
p
( )
( )
p
T
C =
= + −
= −
v t
v ω p x t
t v
p x t ω
J
t
![Page 41: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/41.jpg)
Friction Constraint
The friction force is limited by the normal force.
Coulomb’s Law: t n
In 2D:n t n −
3D is a bit more complicated. See the references.
![Page 42: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/42.jpg)
Constraints Solvers
⚫ We have a bunch of constraints.
⚫ We have unknown constraint forces.
⚫ We need to solve for these constraint forces.
⚫ There are many ways different ways to compute
constraint forces.
![Page 43: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/43.jpg)
Constraint Solver Types
⚫ Global Solvers (slow)
⚫ Iterative Solvers (fast)
![Page 44: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/44.jpg)
Solving a Chain
1
2
3
Global:
solve for 1, 2, and 3
simultaneously.
Iterative:
while !done
solve for 1
solve for 2
solve for 3
1m
2m
3m
![Page 45: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/45.jpg)
Sequential Impulses (SI)
⚫ An iterative solver.
⚫ SI applies impulses at each constraint to correct the
velocity error.
⚫ SI is fast and stable.
⚫ Converges to a global solution.
![Page 46: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/46.jpg)
Why Impulses?
⚫ Easier to deal with friction and collision.
⚫ Lets us work with velocity rather than acceleration.
⚫ Given the time step, impulse and force are
interchangeable.
h=P F
![Page 47: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/47.jpg)
Sequential Impulses
Step1:
Integrate applied forces, yielding tentative
velocities.
Step2:
Apply impulses sequentially for all constraints,
to correct the velocity errors.
Step3:
Use the new velocities to update the positions.
![Page 48: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/48.jpg)
Step 1: Newton’s Law
a c= +Mv F F
We separate applied forces and
constraint forces.
mass matrix
![Page 49: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/49.jpg)
Step 1: Mass Matrix
0 0
0 0
0 0
m
m
m
=
M
Particle
Rigid Body m =
E 0M
0 I
May involve multiple particles/bodies.
![Page 50: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/50.jpg)
Step 1: Applied Forces
⚫ Applied forces are computed according to some law.
⚫ Gravity: F = mg
⚫ Spring: F = -kx
⚫ Air resistance: F = -cv2
![Page 51: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/51.jpg)
Step 1 :
Integrate Applied Forces
1
2 1 ah −= +v v M F
Euler’s Method for all bodies.
This new velocity tends to violate the velocity
constraints.
![Page 52: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/52.jpg)
Step 2:
Constraint Impulse
The constraint impulse is just the time step
times the constraint force.
c ch=P F
![Page 53: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/53.jpg)
Step 2:
Impulse-Momentum
Newton’s Law for impulses:
c =M v P
In other words:
1
2 2 c
−= +v v M P
![Page 54: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/54.jpg)
Step 2:
Computing Lambda
For each constraint, solve these for :
1
2 2
2 0
c
T
c
b
−= +
=
+ =
v v M P
P J
Jv
Newton’s Law:
Virtual Work:
Velocity Constraint:
Note: this usually involves one or two bodies.
![Page 55: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/55.jpg)
Step 2: Impulse Solution
( )2
1
1
C
C T
m b
m
−
= − +
=
Jv
JM J
The scalar mC is the effective mass seen by
the constraint impulse:
Cm C =
![Page 56: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/56.jpg)
Step 2: Velocity Update
1
2 2
T
c
c
−
=
= +
P J
v v M P
Now that we solved for lambda, we can use it
to update the velocity.
Remember: this usually involves one or two bodies.
![Page 57: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/57.jpg)
Step 2: Iteration
⚫ Loop over all constraints until you are done:
⚫ - Fixed number of iterations.
⚫ - Corrective impulses become small.
⚫ - Velocity errors become small.
![Page 58: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/58.jpg)
Step 3: Integrate Positions
2 1 2h= +x x v
Use the new velocity to integrate all
body positions (and orientations):
This is the symplectic Euler integrator.
![Page 59: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/59.jpg)
Extensions to Step 2
⚫ Handle position drift.
⚫ Handle force limits.
⚫ Handle inequality constraints.
⚫ Warm starting.
![Page 60: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/60.jpg)
Handling Position Drift
Velocity constraints are not obeyed precisely.
Joints will fall apart.
![Page 61: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/61.jpg)
Baumgarte Stabilization
Feed the position error back into the velocity constraint.
0BC Ch
= + =JvNew velocity constraint:
Bias factor: 0 1
![Page 62: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/62.jpg)
Baumgarte Stabilization
What is the solution to this?
0C Ch
+ =
First-order differential equation …
![Page 63: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/63.jpg)
Answer
0 expt
C Ch
= −
( )exp t−
![Page 64: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/64.jpg)
Tuning the Bias Factor
⚫ If your simulation has instabilities, set the bias factor to
zero and check the stability.
⚫ Increase the bias factor slowly until the simulation
becomes unstable.
⚫ Use half of that value.
![Page 65: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/65.jpg)
Handling Force Limits
First, convert force limits to impulse limits.
impulse forceh =
![Page 66: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/66.jpg)
Handling Impulse Limits
Clamping corrective impulses:
( )min maxclamp , , =
Is it really that simple?
Hint: no.
![Page 67: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/67.jpg)
How to Clamp
⚫ Each iteration computes corrective impulses.
⚫ Clamping corrective impulses is wrong!
⚫ You should clamp the total impulse applied over the
time step.
⚫ The following example shows why.
![Page 68: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/68.jpg)
Example: 2D Inelastic Collision
v
P
A Falling Box
P
Global Solution 1
2m=P v
![Page 69: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/69.jpg)
Iterative Solution
1P 2P
iteration 1
constraint 1 constraint 2
Suppose the corrective impulses are too strong.
What should the second iteration look like?
![Page 70: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/70.jpg)
Iterative Solution
1P 2P
iteration 2
To keep the box from bouncing, we need
downward corrective impulses.
In other words, the corrective impulses are
negative!
![Page 71: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/71.jpg)
Iterative Solution
But clamping the negative corrective impulses
wipes them out:
clamp( , 0, )
0
=
=
This is one way to introduce jitter into
your simulation. ☺
![Page 72: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/72.jpg)
Accumulated Impulses
⚫ For each constraint, keep track of the total impulse
applied.
⚫ This is the accumulated impulse.
⚫ Clamp the accumulated impulse.
⚫ This allows the corrective impulse to be negative yet the
accumulated impulse is still positive.
![Page 73: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/73.jpg)
New Clamping Procedure
1. Compute the corrective impulse, but don’t
apply it.
2. Make a copy of the old accumulated impulse.
3. Add the corrective impulse to the accumulated
impulse.
4. Clamp the accumulated impulse.
5. Compute the change in the accumulated
impulse using the copy from step 2.
6. Apply the impulse delta found in Step 5.
![Page 74: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/74.jpg)
Handling Inequality
Constraints
⚫ Before iterations, determine if the inequality constraint is
active.
⚫ If it is inactive, then ignore it.
⚫ Clamp accumulated impulses:
0 acc
![Page 75: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/75.jpg)
Inequality Constraints
A problem:
overshoot
active inactive active
gravity
Aiming for zero overlap leads to JITTER!
![Page 76: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/76.jpg)
Preventing Overshoot
( )slopCh
= + −Jv
Allow a little bit of penetration (slop).
If separation < slop
C = Jv
Else
Note: the slop will be negative (separation).
![Page 77: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/77.jpg)
Warm Starting
⚫ Iterative solvers use an initial guess for the lambdas.
⚫ So save the lambdas from the previous time step.
⚫ Use the stored lambdas as the initial guess for the new
step.
⚫ Benefit: improved stacking.
![Page 78: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/78.jpg)
Step 1.5
⚫ Apply the stored impulses.
⚫ Use the stored impulses to initialize the accumulated
impulses.
![Page 79: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/79.jpg)
Step 2.5
⚫ Store the accumulated impulses.
![Page 80: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/80.jpg)
Further Reading &
Sample Code
⚫ http://www.gphysics.com/downloads/
![Page 81: Modeling and Solving ConstraintsBasic Idea ⚫ Constraints are used to simulate joints, contact, and collision. ⚫ We need to solve the constraints to stack boxes and to keep ragdoll](https://reader034.vdocuments.us/reader034/viewer/2022042300/5ecb58c67d2ecc3f52110972/html5/thumbnails/81.jpg)
Box2D
⚫ An open source 2D physics engine.
⚫ http://www.box2d.org
⚫ Written in C++.