modeling and solving constraints
play

Modeling and Solving Constraints Erin Catto Blizzard Entertainment - PowerPoint PPT Presentation

Modeling and Solving Constraints Erin Catto Blizzard Entertainment 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.


  1. Modeling and Solving Constraints Erin Catto Blizzard Entertainment

  2. 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.

  3. Overview � Constraint Formulas � Jacobians, Lagrange Multipliers � Modeling Constraints � Joints, Motors, Contact � Building a Constraint Solver � Sequential Impulses

  4. Contact and Friction Constraint Types

  5. Constraint Types Ragdolls

  6. Particles and Cloth Constraint Types

  7. Show Me the Demo!

  8. Bead on a 2D Rigid Wire C x y = ( , ) 0 Implicit Curve Equation: This is the position constraint.

  9. How does it move? The normal vector is perpendicular to the velocity. n v = n v dot( , ) 0

  10. Enter The Calculus Position Constraint: ⎡ ⎤ x = ⎢ ⎥ x = x C ( ) 0 ⎣ ⎦ y If C is zero, then its time derivative is zero. & C = 0 Velocity Constraint:

  11. Velocity Constraint & C = 0 � Velocity constraints define the allowed motion. � Next we’ll show that velocity constraints depend linearly on velocity.

  12. The Jacobian Due to the chain rule the velocity constraint has a special structure: ⎡ ⎤ & x = ⎢ ⎥ & C = Jv v & ⎣ ⎦ y J is a row vector called the Jacobian. J depends on position. The velocity constraint is linear .

  13. The Jacobian The Jacobian is perpendicular to the velocity. J T v & C = = Jv 0

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

  15. Lagrange Multiplier Intuitively the constraint force F c is parallel to the normal vector. F c v Direction known . = λ F J T Magnitude unknown . c implies

  16. Lagrange Multiplier � The Lagrange Multiplier (lambda) is the constraint force signed magnitude. � We use a constraint solver to compute lambda. � More on this later.

  17. 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.

  18. Velocity Transform & v J C Cartesian Constraint Space Space Velocity Velocity & C = Jv

  19. Force Transform λ F J T c Constraint Cartesian Space Space Force Force = λ F J T c

  20. Refresher: Work and Power Work = Force times Distance Work has units of Energy (Joules) Power = Force times Velocity (Watts) ( ) P = F V dot ,

  21. Principle of Virtual Work Principle: constraint forces do no work. = λ F J T We can ensure this by using: c Proof (compute the power): ( ) T = = λ = λ = F v J v Jv T T P 0 c c The power is zero, so the constraint does no work.

  22. Constraint Quantities C Position Constraint & C Velocity Constraint J Jacobian λ Lagrange Multiplier

  23. 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.

  24. Addendum: Modeling Time Dependence � Some constraints, like motors, have prescribed motion. � This is represented by time dependence. ( ) t = x C , 0 Position: & = + = Jv C b t ( ) 0 Velocity: velocity bias

  25. Example: Distance Constraint = − x Position: C L x C = x v T & L Velocity: y x ⎡ ⎤ x = ⎢ ⎥ x Jacobian: ⎣ ⎦ y particle = x T J x b = λ is the tension Velocity Bias: 0

  26. Gory Details ( ) dC d = + − 2 2 x y L dt dt ( ) 1 d dL = + − 2 2 x y + dt dt 2 2 2 x y ( ) + 2 xv yv = x y − 0 + 2 2 2 x y T ⎡ ⎤ ⎡ ⎤ x v v T x 1 = = x ⎢ ⎥ ⎢ ⎥ x + ⎣ ⎦ ⎣ v y ⎦ 2 2 x y y

  27. 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 …

  28. A Recipe for J � Use geometry to write C . � Differentiate C with respect to time. � Isolate v . � Identify J and b by inspection. & = + Jv C b

  29. Constraint Potpourri � Joints � Motors � Contact � Restitution � Friction

  30. T x = x J Joint: Distance Constraint g m λ = T J a x F = c F v y

  31. Motors A motor is a constraint with limited force (torque). Example θ = θ − C sin t − ≤ λ ≤ 10 10 A Wheel Note: this constraint does work.

  32. Velocity Only Motors Example ω & = ω − C 2 − ≤ λ ≤ 5 5 Usage: A wheel that spins at a constant rate. We don’t care about the angle.

  33. 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: t ≥ x C ( , ) 0

  34. Inequality Constraints The corresponding velocity constraint: C ≤ 0 If & C ≥ 0 enforce: Else skip constraint

  35. Inequality Constraints ≤ λ ≤ ∞ 0 Force Limits: Inequality constraints don’t suck .

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

  37. Non-Penetration Constraint body 2 n = δ C δ p (separation) body 1

  38. Non-Penetration Constraint & C = − ⋅ v v n ( ) p 2 p 1 ( ) ( ) = ⎡ + × − − − × − ⎤ ⋅ v ω p x v ω p x n ⎣ ⎦ 2 2 2 1 1 1 − T ⎡ ⎤ ⎡ n ⎤ v 1 ⎢ ⎥ ⎢ ⎥ ( ) − − × p x n ω ⎢ ⎥ ⎢ ⎥ = ⎢ 1 1 ⎥ ⎢ ⎥ Handy Identities n v ⎢ ⎥ ⎢ 2 ⎥ ( ) ( ) − × p x n ⋅ × = ω A B C ⎣ ⎦ ⎣ ⎦ 2 2 ( ) ⋅ × = C A B ( ) J ⋅ × B C A

  39. Restitution Relative normal velocity − ⋅ v v n ฀ v ( ) n p 2 p 1 Velocity Reflection + − ≥ − v ev n n Adding bounce as a velocity bias & + − ev − = + ≥ = 0 C v ev b n n n

  40. Friction Constraint Friction is like a velocity-only motor. The target velocity is zero. & C = ⋅ v t p ( ) = ⎡ + × − ⎤ ⋅ v ω p x t ⎣ ⎦ T ⎡ ⎤ ⎡ ⎤ t v = ⎢ ⎥ ⎢ ⎥ ( ) − × p x t ω ⎣ ⎦ ⎣ ⎦ p t J

  41. 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.

  42. 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.

  43. Constraint Solver Types � Global Solvers (slow) � Iterative Solvers (fast)

  44. Solving a Chain Global: λ 1 solve for λ 1, λ 2, and λ 3 simultaneously. m 1 λ 2 Iterative: m 2 while !done solve for λ 1 λ 3 solve for λ 2 m 3 solve for λ 3

  45. 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.

  46. 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. = P F h

  47. 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.

  48. We separate applied forces and mass matrix c F Step 1: Newton’s Law + a F = constraint forces. Mv &

  49. Step 1: Mass Matrix ⎡ ⎤ Particle m 0 0 ⎢ ⎥ = ⎢ M 0 m 0 ⎥ ⎢ ⎥ ⎣ ⎦ 0 0 m ⎡ E 0 ⎤ Rigid Body m = ⎢ M ⎥ 0 I ⎣ ⎦ May involve multiple particles/bodies.

  50. Step 1: Applied Forces � Applied forces are computed according to some law. � Gravity: F = mg � Spring: F = -kx � Air resistance: F = -cv 2

  51. Step 1 : Integrate Applied Forces Euler’s Method for all bodies. − = + v v M F 1 h 2 1 a This new velocity tends to violate the velocity constraints.

  52. Step 2: Constraint Impulse The constraint impulse is just the time step times the constraint force. = P F h c c

  53. Step 2: Impulse-Momentum Newton’s Law for impulses: Δ = M v P c In other words: − = + v v M P 1 2 2 c

  54. Step 2: Computing Lambda For each constraint, solve these for λ : − = + v v M P 1 Newton’s Law: 2 2 c = λ P J T Virtual Work: c + = Jv b 0 Velocity Constraint: 2 Note: this usually involves one or two bodies.

  55. Step 2: Impulse Solution ( ) λ = − + Jv m b C 2 1 = m − C JM J 1 T The scalar m C is the effective mass seen by the constraint impulse: & Δ = λ m C C

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend