Projects Dynamics II Forces, Collisions and Impulse Presentations: Dates: Week 0: Mon, Feb 6 Week 0: Wed, Feb 8 Finals Week: Tues, Feb 4 (:30 :30) room TBA 5 minutes / presentation Schedule now on Web Please send me choice of time/day Assignments Assignment -- Framework Some have been graded If not submitted please do so. Assignment -- Keyframing Due Mon, Jan. Questions? Assignment 3 -- Billiards To be given Monday. Plan Physics 0 for rigid body animation Monday: translation and rotational dynamics Today: Forces, impacts, and collisions Next Monday: Numerical integration. Next Wednesday: Applications (including particle systems) But first Motivational Films Educational animations by Jim Blinn Motivational Film Mathematica: The Theorem of Pythagoras (988) JPL Cal Tech Now at Microsoft
Motivational Film The Mechanical Universe (984) Let s get started Physics for Rigid Body Dynamics Last class: Linear/ Rotational Motion Today: Collisions Wednesday: Numerical Integration Laws of Motion Linear Motion Law I Every object in a state of uniform motion tends to remain in that state of motion unless an external force is applied to it. (Inertia) Law II: The acceleration of a body is proportional to the resulting force acting on the body, and this acceleration is in the same direction as the force. Law III: For every action there is an equal and opposite reaction. For Linear Physical Motion Mass Measure of the amount of matter in a body From Law II: Measure of the a body s resistance to motion Velocity Change of motion with respect to time Acceleration Change of velocity with respect to time Force In short, force is what makes objects accelerate Momentum mass x velocity Another way of stating Law I: Momentum is conserved Rotational Motion For Rotational Physical Motion Inertia Measure of the amount/distribution of matter in a body From Law II: Measure of the a body s resistance to motion Angular Velocity Change of rotation with respect to time Angular Acceleration Change of velocity with respect to time Torque In short, torque is what makes objects rotate Angular Momentum Inertia x velocity Another way of stating Law I: Momentum is conserved Where we are Object properties Position, orientation Linear and angular velocity Linear and angular momentum mass Update object properties Calculate forces Calculate accelerations Using mass, momenta
Where we are State of object at any given time s( t) R( t) S( t) = M ( t) L( t) position rotation (in world coords) momentum angular momentum Where we are Derivative of object state s& ( t) v( t) R& ( t) ( t) R( t) S& ω ( t) = = M& ( t) F( t) L& ( t) τ ( t) Putting it all together Step Calculate Forces, F(t), τ(t) Step Integrate position/rotation s(t +Δt) = s(t) + v(t)δt R(t +Δt) = R(t) + (ω(t)*r(t)) Δt /* CAREFUL HERE */ r(t +Δt) = s(t +Δt) + r body R(t +Δt) Update Momentum (integrate accelleration) M(t +Δt) = M(t) + F(t) Δt L(t +Δt) = L(t) + τ(t) Δt Putting it all together Step Calculate Forces, F(t), τ(t) Step Integrate position/rotation s(t +Δt) = s(t) + v(t)δt q(t +Δt) = q(t) + 0.5 (ω(t)q(t)) Δt /* normalize to avoid problems */ R(t +Δt) = quattorot (q(t +Δt) ) r(t +Δt) = s(t +Δt) + r body R(t +Δt) Update Momentum (integrate accelleration) M(t +Δt) = M(t) + F(t) Δt L(t +Δt) = L(t) + τ(t) Δt Putting It all together Step 3 Calculate velocities (for next step) v(t +Δt) = M(t +Δt)/m I - (t +Δt) = R(t +Δt)I - body R(t +Δt)T ω(t +Δt) = + I - (t +Δt)L(t +Δt) Go to step Questions? Useful forces Gravity Friction Impulse Spring Wind Add your own 3
Gravity Gravity is an attractive force between all pairs of massive objects in the universe. The gravitational force between two objects is given by a (fairly) simple mathematical equation. m m F = G r Where m and m are the masses of the two objects r is the distance between the two objects G is the universal gravity constant = 6.67 x 0 - Nm / kg Gravity For objects interacting on this earth, the acceleration due to gravity can be calculated using the radius of the earth. g = 9.8 m / sec g = 3 ft / sec This acceleration is always towards the earth s surface. Friction Arises from interaction of surfaces in contact. Always works against the direction of relative motion of two objects. Friction Static Friction For objects not in motion Fraction of the normal component of force Amount of force need to get object from rest moving Kinetic friction For objects in motion Fraction of the normal component of force Amount of resistance due to friction Static Friction Kinetic Friction Supporting object Resting contact Normal force F F s F N Supporting object Resting contact Normal force F F k F N v Static friction F s = u s * F N Kinetic friction F k = u k * F N 4
Friction Surfaces u s u k Dry glass on glass 0.94 0.4 Dry iron on iron. 0.5 Dry rubber on pavement 0.55 0.4 Dry steel on steel 0.78 0.4 Dry Teflon on Teflon 0.04 0.04 Dry wood on wood 0.38 0. Ice on Ice 0. 0.03 Oiled steel on steel 0. 0.08 Springs Force applied by stretching a spring. Given by Hooke s Law restoring force due to a spring is proportional to the length that the spring is stretched acts in the opposite direction. F = -kx Springs Hooke s Law F = -kx k = spring constant Given in N/m Large k stronger springs Small k looser springs Springs Damping Decreases spring force proportional to velocity Springs Damping Damping specified by damping coefficient, k d Damping and Springs F = kx k d dx dt Springs Useful for: Simulate collections of connected particles or rigid bodies Example: cloth, paper, etc. Damping required to make solutions stable Can also be used in collision detection (impulse forces) 5
Wind Define a force field Force varies in space and time Add your own Most difficult part is mathematically describing the force Wind, turbulence See Wejchert paper in READING LIST Physics for game development book has a bunch Questions Impulse Law III: For every action there is an equal and opposite reaction. Impulse is the equal and opposite reaction after a collision Impulse Impulse A force that acts over a very short period of time. Gives change in momentum + t Linear Impulse = F ( t) dt = M after M before t + t Angular Impulse = τ (t)dt = L after L before t Impulse and Collision At the time of collision, each object applies an impulse force on the other. Magnitude is the same Opposite in Direction Following Law III Collisions Law says that momentum is conserved When objects collide with masses m and m Velocities v and v ( v + mv) before = ( mv + mv m ) after Link http://www.phy.ntnu.edu.tw/ntnujava/index.php? topic=5.0 6
Kinetic Energy Energy required to accelerate a body from rest KElinear = mv KEangular = Energy is conserved Iω Types of collisions Elastic Kinetic energy is conserved No kinetic energy is lost Example: flubber super ball Inelastic All kinetic energy is lost Colliding objects stick together Energy converted to heat, sound, damage Example: clay falling on a hard floor Coefficient of restitution Most collisions lie somewhere between perfectly elastic and perfectly inelastic Gives a measure of the elasticity during an impact ( v v) e = ( v v ) after before Coefficient of restitution Perfectly elastic = Perfectly inelastic = 0 Most collisions Somewhere between 0 and Link http://www.phy.ntnu.edu.tw/ntnujava/ index.php?topic=4.0 Line of action Line of action Line perpendicular to the colliding surfaces Central The line of action passes through the center of mass Always true for spheres Direct Velocities is along the line of action Oblique The velocities are not along the line of action Line of action 7
Impulse Force is a vector Only velocities along line of action need be considered Link Calculating Impulse Force Linear Remember J = m v v ) J = m v v ) ( after before ( v v) e = ( v v ) after before ( after before Calculating Impulse Forces Calculating Impulse Force Linear After doing some algebra ( v v) before( e + ) J = + m m Note: J and v s are scalar giving the values along the line of action Calculating new velocities Once we know J Calculating Impulse Force Angular Jn v after = v before + m v after = v before Jn m Where n is a normalized vector along the line of action. Here, J is a scalar giving the impulse along the line of action Two more unknowns to deal with (ω after for each object) 8
Calculating Impulse Force Separate velocity into components r body (t) = v(t) + ω(t) r body Calculating Impulse Force Luckily we have 4 equations from linear impulse v after + (ω after r ) = (Jn) m + v before + (ω before r ) v after + (ω after r ) = (Jn) m + v before + (ω before r ) from angular impulse (r Jn) = I (ω after ω before ) (r Jn) = I (ω after ω before ) Calculating Impulse Forces Calculating Impulse Force After doing some more algebra ( v v) before( e + ) J = + + n m m [ I ( r n) ] r + n [ I ( r n) ] r Where n a unit vector normal to the surface of contact The v s are scalar velocities along the line of action. Calculating new velocities Once we know J Jn v after = v before + v m after = v before Jn m Questions Let s take a break ω after = ω before + I (r Jn) ω after = ω before + I (r Jn) 9
Collisions and Animation Answers the question, was there a collision Collision Determination If there is a collision, when and where did it occur? Collision Response How does the collision affect the motion of the objects involved? Strictly a kinematic issue Based on position and orientation of objects and how they change over time. Can be determined when after a given time step one object penetrates another Penetrating objects Be careful positions are only approximations False positive okay Missed positive bad Penetrating objects Complexity will depend upon objects being tested for penetration There are many good algorithms and free libraries for collision detection of planar convex polyhedra See Web Page for Survey paper. Major Challenge in collision detection Must check collision of each pair of objects General problem is O(N ) Multiple collisions in a single time step. Efficient collision detection for real time applications is still an active research area Tips Similar to tips for intersection testing for ray tracing Use hierarchical bounding volumes Place simple objects (i.e sphere or box) around complex objects Do initial intersection tests on bounding objects. If ray intersects bounding volume, then test complex bounded object 0
hierarchical bounding volumes hierarchical bounding volumes Considerations Ease of detection Bounding efficiency Other Tips You need only test moving objects for collisions (remember Law ) However, you must test against all other objects, moving or stationary - Spatial Subdivision Subdivide your scene volume into hierarchical regions Create a tree structure that indicates for each region: if the region is empty the object present at that particular region Test collision with objects in volume - Spatial Subdivision Motivation Without spatial subdivision, you will need to query all objects/polygons and test for intersection With spatial subdivision, you know which objects are in which volume so you only test objects that are in the volumes where an object traveling. - Spatial Subdivision Examples Octrees Recursively subdivide volume into equal regions. If subregion is empty, then stop Otherwise further subdivide subregion. Continue until each subregion is empty or contains a single object. BSPTrees Like Octrees but divides space into a pair of subregions Subregions need not be equally spaced Planes separating regions can be placed at object boundaries.
-- Octrees -- Octrees Images from flipcode.com -- Octrees -- BSPTree - Spatial Subdivision Issues Must rebuild tree at each time step Tradeoff Time to build tree vs. Time to check for collisions BSP/OctTrees for static objects Questions? Collision Determination If a collision has been detected, the time and point of impact must be determined By the time a collision is detected, one object has already penetrated another I.e. Collision occurred between time steps Need to backup simulation to the point when collision took place.
Collision Determination Binary search strategy No collision at time t Penetration at time t + Δt Test point at time t between t and t + Δt iterative. If No Collision, test at time between t and t + Δt Else test at time between t and t Iterate until a predefined tolerance is achieved. Point at t i- Collision Determination Linear interpolation strategy s L t = t i + s/l (t i t i- ) Point at t Collision Response Once we have the actual time and point of collision, we can use formula in first half to determine impulse force and new velocities. Collision Response Penalty Method Rather than applying kinematic equations, use a spring to approximate the impulse force. ( v v) before( e + ) J = + + n m m [ I ( r n) ] r + n [ I ( r n) ] r Collision Response Recall Spring force given by Hooke s Law F = -kx Where x is the displacement of the spring k is a spring constant Collision Response Penalty Method Pros Ease of implementation No need to step back to time of collision No need to mess with complex kinematic equations Cons How does one choose k? Must choose carefully else solution may become unstable or in accurate Simply a hueristic hack Your mileage may vary! 3
To sum up Answers the question, was there a collision Collision Determination If there is a collision, when and where did it occur? Collision Response How does the collision affect the motion of the objects involved? Questions? Putting it all together Object properties Position, orientation Linear and angular velocity Linear and angular momentum mass Update object properties Calculate forces Calculate accelerations Using mass, momenta Putting it all together Step Calculate Forces, F(t), τ(t) Step Integrate position/rotation s(t +Δt) = s(t) + v(t)δt q(t +Δt) = q(t) + 0.5 (ω(t)q(t)) Δt /* normalize to avoid problems */ R(t +Δt) = quattorot (q(t +Δt) ) r(t +Δt) = s(t +Δt) + r body R(t +Δt) Update Momentum (integrate accelleration) M(t +Δt) = M(t) + F(t) Δt L(t +Δt) = L(t) + τ(t) Δt Putting it all together Step 3 Calculate velocities (for next step) v(t +Δt) = M(t +Δt)/m + impulse velocity I - (t +Δt) = R(t +Δt)I - body R(t +Δt) T ω(t +Δt) = I - (t +Δt)L(t +Δt) + impulse velocity Go to step Questions? Video Let s see how this all looks when assembled properly Rigid Body Dynamics By James Hahn (also at Ohio State at the time) Accompanying video to his paper B-D Tree By Doug L. James (CMU) If falling chairs is your thing. Next Time Numerical Integration Assignment #3 Questions? 4