Transcript PowerPoint

Baraff, 1991
Animation
CS 551 / 651
Lecture 6
Rigid-body Simulation
Assignment 1
Rigid-body Simulator
Goal: To demonstrate understanding of rigid-body
dynamics by writing a simulator
• 3ds file loader (given)
• Compute COM and MOI (given)
• User-selected force vector (how?)
• Compute location of impact (ray / polygon intersection)
• Compute change in linear and angular accelerations (Hecker)
• Animate…
Rigid-body Simulator
Not permitted resources
•
Physical simulation source code
– Not from web, books, bathroom wall…
Permitted resources
•
All books (physics, graphics, C++, game design, …)
•
Graphics interface libraries
•
File loader and MOI libraries
Rigid-body Simulator
Deliverables
• Load any legal (closed) 3ds model
an aside…
Closed objects
AKA “solid”
More rigorously: closed, orientable manifolds
• Local neighborhood of all points isomorphic to disc
• Boundary partitions space into interior & exterior
Yes
No
Manifold
Examples of manifold objects:
• Sphere
• Torus
• Well-formed
CAD part
Back-Face Culling
Examples of non-manifold objects:
• A single polygon
• A terrain or height field
• polyhedron w/ missing face
• Anything with cracks or holes in
boundary
• one-polygon thick lampshade
Rigid-body Simulator
Deliverables (basic)
• Load any legal (closed) 3ds model
• Define an arbitrary force vector
• Animate the model as is moves
Rigid-body Simulator
Deliverables (intermediate)
• Add gravity and drop object to the ground. Use
constraint forces to make it rest there
• Weld a spring to a vertex of the model and suspend
model by spring from ceiling
– Why springs? Because it is much more
complicated to force the model to hang from a
string (or bar) of fixed length… more constraints to
worry about
Rigid-body Simulator
Deliverables (advanced)
• Add more objects and springs
– Newton’s Cradle
– Join two objects with springs
– Suspend one object by spring and
drop other objects on it
• Implement constrained dynamics
– Replace springs with rods
Rigid-body Simulator
Grading will take place during a demo you’ll
provide for the TA
• Time TBA, but as early as 6:15 Wed, Sep 19th
• Either bring your machine to him
• Or make sure it works on Windows machine with
VisualStudio .net
– Machines in Stacks and Small Hall should be set
up this way
Reading for Monday
Prepare three questions for each paper
Timewarp Rigid Body Simulation, B. Mirtich,
SIGGRAPH 2000.
Stephen Chenney and D.A.Forsyth, "Sampling
Plausible Solutions to Multi-Body Constraint
Problems". SIGGRAPH 2000 Conference
Proceedings, pages 219-228, July 2000.
Collisions
We’re in 2D… Collisions are:
• Vertex / edge
• Vertex / vertex
• Edge / edge
Compute normal to collision
• v/e: perpendicular to edge (pointing towards A by convention)
• e/e: perpendicular to edge
• v/v: something reasonable (perhaps use an edge-perp)
Collisions
Compute relative normal velocity
• vf AB  n  (v AP
 v BP )  n
– Must be negative for a collision to
take place
– If equal to 0… resting contact
(special case)
After collision is detected
Consider applying a force to both bodies
• This is how nature “simulates” collisions
• Already interpenetrating objects will remain in this
state for at least one more time step
– Cannot instantaneously change velocity
– Forces need time to be integrated to accelerations
and velocities
After collision is detected
We need instantaneous change in velocity
• Impulse
– This is a hack that gets us out of the jam we
created when assuming impenetrable bodies exist
– Generalization of subtle surface properties
– Like simulating a large force for a small time step
– Will change velocity like we need
Calculating impulse
Duration of impulse is “no time”
• This is a small amount of time
• All other forces are ignored during this period
No friction
Coefficient of resitution
• Models complicated compression and restitution of
impacting bodies
• Models dissipation of energy
Coefficient of restitution
AB

v
 n  v
AB

n
 = 1  superball (perfectly elastic)
 = 0  clay (perfectly inelastic)
Calculating an impulse
Solve for one number, j
• Apply j in direction of n to A
• Apply j in direction of –n to B
equal and opposite
Computing Impulse
1st: Assume objects cannot rotate
2nd: Use definition of coeff. of rest. to derive
a second set of v+ equations
3rd: Use substitution to solve for j
Computing impulse
Things to note:
• n doesn’t have to be normalized
• A or B can be fixed by setting mass to infinity
• If MA = 1, MB = inf, vB = 0, =1
– Computes reflection of vA about n
Accounting for rotation
Consider velocity of collision point P after collision
Derived from two equations
Accounting for rotation
Returning to elasticity
Start substituting
Solve for j
Notes
Time of impact
• Must apply impulse exactly at time of impact
– After detecting interpenetration, use binary search (or more
sophisticated) to fine tune
– Beware of “tunneling” when dt is so large collisions are
missed
• Edge/edge collisions are modeled as point/point in this system
• Only two colliding bodies at a time
• 3D is harder because of variety of collision types
Numerical Integration
(from Dr. Tom Hobbs Systems Ecology course at Colorado State)
Y = f(t), unknown
f(t+t), unknown
Y
dy
dx
t, specified
t
known
Example
dy
 6 y .007 y 2
dt
Analytical solution to dy/dt
Y0 = 10
 t = 0.5
point to
estimate
Euler (pronounced “oiler”)
y0 = 10
analytical y
k1 = dy/dt at y0
y
k1 = 6*10-.007*(10)2
y = k1*t
estimated y
yest= y0 + y
y
 t = 0.5
Runge-Kutta (pronounced Run-gah Kut-tah)
point to
estimate
Problem: estimate the slope to
calculate y
y
dy
 6 y .007 y 2
dt
 t = 0.5
Runge-Kutta (4th order)
( xt  t / 2, yt  k1t / 2)
f '(t , y )  derivative at (t , y )
slope = k1
k1  f '(t , y )
k1t / 2 y
k2  f '(t  t / 2, y  k1t / 2)
k3  f '(t  t / 2, y  k2 t / 2)
k4  f '(t  t , y  k3 t )
(t , y )
t/2
t
1
yt   yt  t (k1  2k2  2k3  k4 )
6
Step 1: Evaluate slope at current value of
state variable.
y0 = 10
k1 = dy/dt at y0
k1 = 6*10-.007*(10)2
k1 = 59.3
k1=slope 1
Step 2: Calculate y1at t +t/2 using k1.
Evaluate slope at y1.
y1 = y0 + k1* t /2
y1 = 24.82
k2 = dy/dx at y1
k2 = 6*24.8-.007*(24.8)2
k2 = 144.63
y1
 t = 0.5/2
k2=slope 2
Step 3: Calculate y2 at t +t/2 using k2.
Evaluate slope at y2.
y2 = y0 + k2* t /2
y2 = 46.2
k3 = dy/dt at y2
k3 = 6*46.2-.007*(46.2)2
k3 = 263.0
y2
 t = 0.5/2
k3 = slope 3
Step 4: Calculate y3 at t +t using k3.
Evaluate slope at y3.
y3 = y0 + k3* t
y3
y3 =141.0
k4 = dy/dt at y2
k4 = 6*141.0-.007*(141.0)2
k4 = 706.9
y2
 t = 0.5
k4 = slope 4
Step 5: Calculate weighted slope.
Use weighted slope to estimate y at t +t
weighted slope =
Yt 
1
(k1  2k2  2k3  k4 )
6
1
 Yt  t (k1  2k2  2k3  k4 )
6
true value
weighted slope
estimated value
 t = 0.5
Conclusions
•
4th order Runge-Kutta offers substantial improvement over Eulers.
•
Both techniques provide estimates, not “true” values.
•
The accuracy of the estimate depends on the size of the step used in the
algorithm.
Analytical
Runge-Kutta
Euler