Modeling and Solving Constraints

Slides:



Advertisements
Similar presentations
AP Physics C Mechanics Review.
Advertisements

Work, Energy, and Power AP Physics C.
Real-Time Game Physics
Physics for Game Programmers Contacts or “How (Not) To Make It Stick” Gino van den Bergen
Lecture 5: Constraints I
© 2011 Autodesk Freely licensed for use by educational institutions. Reuse and changes require a note indicating that content has been modified from the.
Physics 111: Mechanics Lecture 10 Dale Gary NJIT Physics Department.
1Notes  Reference  Witkin and Baraff, “Physically Based Modelling” course, SIGGRAPH 2001  Link on the course website.
1cs533d-winter-2005 Notes  Assignment 2 going okay? Make sure you understand what needs to be done before the weekend  Read Guendelman et al, “Nonconvex.
Chapter 6 Momentum and Collisions. Momentum The linear momentum of an object of mass m moving with a velocity v is defined as the product of the mass.
UNC Chapel Hill S. Redon - M. C. Lin Rigid body dynamics II Solving the dynamics problems.
Physics of Rolling Ball Coasters
Manipulator Dynamics Amirkabir University of Technology Computer Engineering & Information Technology Department.
Physics 1901 (Advanced) A/Prof Geraint F. Lewis Rm 557, A29
1cs533d-winter-2005 Notes  Assignment 2 instability - don’t worry about it right now  Please read D. Baraff, “Fast contact force computation for nonpenetrating.
3.7. O THER G AME P HYSICS A PPROACHES Overview of other game engine physics approaches.
Velocities and Static Force
FE Exam: Dynamics review
Reference Book is. NEWTON’S LAW OF UNIVERSAL GRAVITATION Before 1687, clear under- standing of the forces causing plants and moon motions was not available.
Fast and Simple Physics using Sequential Impulses
Lecture VII Rigid Body Dynamics CS274: Computer Animation and Simulation.
Game Physics – Part IV Moving to 3D
Game Physics – Part I Dan Fleck Coming up: Rigid Body Dynamics.
Erin Catto Blizzard Entertainment Numerical Integration.
Momentum, Impulse, And Collisions
ME451 Kinematics and Dynamics of Machine Systems
ME451 Kinematics and Dynamics of Machine Systems Numerical Solution of DAE IVP Newmark Method November 1, 2013 Radu Serban University of Wisconsin-Madison.
ME451 Kinematics and Dynamics of Machine Systems Dynamics of Planar Systems December 1, 2011 Solving Index 3 DAEs using Newmark Method © Dan Negrut, 2011.
Work, Energy & Power AP Physics 1. There are many different TYPES of Energy. Energy is expressed in JOULES (J) Energy can be expressed more specifically.
Chapter 7 Energy of a System. Introduction to Energy A variety of problems can be solved with Newton’s Laws and associated principles. Some problems that.
Modeling and Solving Constraints Erin Catto Blizzard Entertainment.
AP Physics C: Mechanics Chapter 11
Mechanics Topic 2.3 Work, Energy and Power. Work A simple definition of work is the force multiplied by the distance moved However this does not take.
When the axis of rotation is fixed, all particles move in a circle. Because the object is rigid, they move through the same angular displacement in the.
Chapter 7 Linear Momentum. MFMcGraw-PHY 1401Chap07b- Linear Momentum: Revised 6/28/ Linear Momentum Definition of Momentum Impulse Conservation.
Computer Animation Rick Parent Computer Animation Algorithms and Techniques Optimization & Constraints Add mention of global techiques Add mention of calculus.
Advanced Computer Graphics Rigid Body Simulation Spring 2002 Professor Brogan.
University of Texas at Austin CS 378 – Game Technology Don Fussell CS 378: Computer Game Technology Physics for Games Spring 2012.
Exam 2 Review 8.02 W08D1. Announcements Test Two Next Week Thursday Oct 27 7:30-9:30 Section Room Assignments on Announcements Page Test Two Topics: Circular.
Chapter 6 Momentum and Collisions. Momentum The linear momentum of an object of mass m moving with a velocity is defined as the product of the mass and.
Rigid Body Dynamics (II). Bodies intersect ! classify contacts Bodies separating –v rel >  –No response required Colliding contact (Last time) –v rel.
Work and Energy. Scalar (Dot) Product When two vectors are multiplied together a scalar is the result:
CS274 Spring 01 Lecture 7 Copyright © Mark Meyer Lecture VII Rigid Body Dynamics CS274: Computer Animation and Simulation.
6.4 Vectors and Dot Products Day
A body experiences a change in energy when one or more forces do work on it. A body must move under the influence of a force or forces to say work was.
Linear Momentum and Collisions
Advanced Games Development Game Physics CO2301 Games Development 1 Week 19.
ME451 Kinematics and Dynamics of Machine Systems Dynamics of Planar Systems December 9, 2010 Solving Index 3 DAEs using Newmark Method © Dan Negrut, 2010.
Two-Dimensional Rotational Dynamics 8.01 W09D2 Young and Freedman: 1.10 (Vector Product), , 10.4, ;
Dynamics. Motion with Regard to Mass Particle Dynamics Mass concentrated in point Newton’s Equation Governs Motion f = M x.
Particle Kinematics Direction of velocity vector is parallel to path Magnitude of velocity vector is distance traveled / time Inertial frame – non accelerating,
PHY 151: Lecture 7A 7.1 System and Environments 7.2 Work Done by a Constant Force 7.3 Scalar Product of Two Vectors 7.4 Work Done by a Varying Force 7.5.
ME451 Kinematics and Dynamics of Machine Systems Dynamics of Planar Systems December 9, 2010 Solving Index 3 DAEs using Newmark Method © Dan Negrut, 2010.
Advanced Computer Graphics Rigid Body Simulation
Momentum and Collisions
Momentum and Collisions
Character Animation Forward and Inverse Kinematics
Manipulator Dynamics 1 Instructor: Jacob Rosen
PHYS 1443 – Section 003 Lecture #18
WORK And Energy and Power.
3.7. Other Game Physics Approaches
Handling of Resting Contact
Linear Momentum and Collisions
PHYS 211 Exam 1 HKN Review Session
Work AP Physics C.
Work, Energy, and Power AP Physics C.
AP Physics C Work, Energy, and Power.
Work, Energy, and Power AP Physics C.
Work, Energy, and Power AP Physics.
Presentation transcript:

Modeling and Solving Constraints Erin Catto Blizzard Entertainment Just one approach, but a ubiquitous one.

Executive Summary 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.

Overview Constraint Formulas Deriving Constraints Joints, Motors, Contact Building a Constraint Solver

Constraint Types Contact and Friction

Constraint Types Ragdolls

Constraint Types Particles and Cloth

Show Me the Demo!

Motivation Bead on a Rigid Wire (2D) Implicit Function This is a constraint equation!

Velocity The normal vector is perpendicular to the curve. This is constraint on the velocity. So this dot product is zero:

Velocity Constraint Position Constraint: If C is zero, then its time derivative should be zero. Cdot = dC/dt Velocity Constraint:

Velocity Constraint Velocity constraints define the allowed motion. Velocity constraints can be satisfied by applying impulses. More on that later.

The Jacobian Due to the chain rule the velocity constraint has a special structure: J is the Jacobian.

The Jacobian The Jacobian is perpendicular to the velocity. J maps Cartesian motion into constraint motion.

The Velocity Map J v Cartesian Space Velocity Constraint Space

Constraint Force Assume the wire is frictionless. What is the force between the wire and the bead?

Lagrange Multiplier Intuitively the constraint force Fc is parallel to the normal vector. JT maps forces in the constraint space into Cartesian space. Direction known. Magnitude unknown. implies

Lagrange Multiplier Lambda is the constraint force signed magnitude. How do we compute lambda? That is the solver’s job. Solvers are discussed later.

The Force Map Constraint Space Force Cartesian Space Force

Work, Energy, and Power Work = Force times Distance Work has units of Energy (Joules) Power = Force times Velocity (Watts)

Principle of Virtual Work Constraint forces do no work, so they must be perpendicular to the allowed velocity. Assertion: Proof: So the constraint force doesn’t affect energy.

Constraint Quantities Position Constraint Velocity Constraint Jacobian Lagrange Multiplier

Why all the Painful Abstraction? To put all manner of constraints into a common form for the solver. To allow us to efficiently try different solution techniques.

Time Dependence Some constraints, like motors, have prescribed motion. This is represented by time dependence. Position: Velocity: velocity bias

Example: Distance Constraint Position: x L y Velocity: particle attached to ground by a massless rod. lambda is the tension. Jacobian: particle Velocity Bias: is the tension

Gory Details

Computing the Jacobian At first, it is not easy to compute the Jacobian. It helps to have the constraint equation first. It gets easier with practice. Try to think in terms of vectors.

A Recipe for J Use geometry to write C. Differentiate C with respect to time. Isolate v. Identify J by inspection (and b). Don’t compute partial derivatives!

Homework Angle Constraint: Point Constraint: Line Constraint:

Newton’s Law We separate applied forces and constraint forces.

Types of Forces Applied forces are computed according to some law: F = mg, F = kx, etc. Constraints impose kinematic (motion) conditions. Constraint forces are implicit. We must solve for constraint forces.

Constraint Potpourri Joints Motors Contact Restitution Friction

Joint: Distance Constraint x y v

Motors A motor is a constraint with limited force (torque). Example A Wheel Note: this constraint does work.

Velocity Only Motors Example Usage: A wheel that spins at a constant rate. We don’t care about the angle.

Inequality Constraints So far we’ve looked at equality constraints (because they are simpler). Inequality constraints are needed for contact, joint limits, rope, etc.

Inequality Constraints What is the velocity constraint? If enforce: Else skip constraint

Inequality Constraints Force Limits: Inequality constraints don’t suck.

Contact Constraint Non-penetration. Restitution: bounce Friction: sliding, sticking, and rolling

Non-Penetration Constraint body 2 (separation) body 1

Non-Penetration Constraint Handy Identities J v

Restitution Relative normal velocity Velocity Reflection Adding bounce as a velocity bias

Friction Constraint Friction is like a velocity-only motor. The target velocity is zero. J v

Friction Constraint The friction force is limited by the normal force. Coulomb’s Law: Or: Where:

What is a Solver? Collect all forces and integrate velocity and position. Apply constraint forces to ensure the new state satisfies the constraints. We must solve for the constraint forces because they are implicit.

Solver Types Global Solvers (slow) Iterative Solvers (fast)

Solving A Chain Global: solve for l1, l2, and l3 simultaneously. l1 l2 Iterative: while !done solve for l1 solve for l2 solve for l3 l3

Sequential Impulses (SI) An iterative solver. SI applies impulses at each constraint to correct velocity errors. SI is fast and stable (usually). Converges to a global solution (eventually).

Why Impulses? Easier to deal with friction and collision. Velocity is more intuitive than acceleration. Given the time step, impulse and force are interchangeable.

Sequential Impulses Step1: Integrate applied forces, yielding new velocities. Step2: Apply impulses sequentially for all constraints, to correct the velocity errors. Step3: Use the new velocities to update the positions.

Step 1 : Integrate Applied Forces Euler’s Method This new velocity tends to violate the velocity constraints.

Step 2: Apply Corrective Impulses For each constraint, solve: Newton: Virtual Work: Velocity Constraint:

Step 2: Impulse Solution The scalar mC is the effective mass seen by the constraint impulse:

Step 2: Velocity Update Now that we solved for lambda, we can use it to update the velocity.

Step 2: Iteration Loop over all constraints until you are done: - Fixed number of iterations. - Corrective impulses become small. - Velocity errors become small.

Step 3: Integrate Positions Use the new velocity: This is the Symplectic Euler integrator.

Extensions to Step 2 Handle position drift. Handle force limits. Handle inequality constraints.

Handling Position Drift Velocity constraints are not obeyed precisely. Joints will fall apart.

Baumgarte Stabilization Feed the position error back into the velocity constraint. New velocity constraint: Bias factor:

Baumgarte Stabilization What is the solution to: ??? ODE … First-order differential equation …

Answer

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.

Handling Force Limits First, convert force limits to impulse limits.

Handling Impulse Limits Clamping corrective impulses: Is it really that simple? Hint: no.

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.

Example: Inelastic Collision v A Falling Box Global Solution

Iterative Solution iteration 1 constraint 1 constraint 2 constraint 1 Suppose the corrective impulses are too strong. What should the second iteration look like?

Iterative Solution iteration 2 To keep the box from bouncing, we need downward corrective impulses. In other words, the corrective impulses are negative!

Iterative Solution But clamping the negative corrective impulses wipes them out: This is a nice way to introduce jitter into your simulation. 

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 when the accumulated impulse is still positive.

New Clamping Procedure Step A: Compute the corrective impulse, but don’t apply it. Step B: Add the corrective impulse to the accumulated impulse. Step C: Clamp the accumulated impulse. Step D: Compute the change in the accumulated impulse. Step E: Apply the impulse found in Step D.

Handling Inequality Constraints Before iterations, determine if the inequality constraint is active. If it is inactive, then ignore it. Clamp accumulated impulses:

Inequality Constraints A problem: overshoot gravity active inactive active Jitter is not nice!

Preventing Overshoot Allow a little bit of penetration (slop). If separation < slop factor Else Note: the slop factor will be negative (separation).

Other Important Topics Warm Starting Split Impulses

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.

Step 1.5 Apply the stored lambdas. Use the stored lambdas to initialize the accumulated impulses.

Step 2.5 Store the accumulated impulses.

Split Impulses Baumgarte stabilization affects momentum. This is bad, bad, bad! Unwanted bounces Spongy contact Jet propulsion

Split Impulses Use different velocity vectors and impulses. Real: Pseudo: Two parallel solvers.

Split Impulses The real velocity only sees pure velocity constraints. The pseudo velocity sees position feedback (Baumgarte). The Jacobians are the same!

Pseudo Velocity The pseudo velocity is initialized to zero each time step. The pseudo accumulated impulses don’t use warm starting (open issue).

Step 3 (revised): Integrate Positions Use the combined velocity:

Further Reading http://www.cs.cmu.edu/~baraff/sigcourse/notesf.pdf http://www.gphysics.com/downloads/ http://www.continuousphysics.com And the references found there.

Box2D Demo An open source 2D physics engine. http://www.gphysics.com/box2d A test bed and a learning aid.