CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using...
Transcript of CS 231 Animation Using Dynamic Simulationvbz/cs231f10/lecture08-10.pdf · CS 231 Animation Using...
1
CS 231
Animation Using Dynamic Simulation
CS 231CS 231
Animation Using Dynamic Simulation Animation Using Dynamic Simulation
What is dynamics for animation?What is dynamics for animation?
forwarddynamics
integrator
graphics
state
Loosely, using physical rulesLoosely, using physical rulesor principles to animate, a or principles to animate, a procedural approach procedural approach
Usually, the use of a forwardUsually, the use of a forwarddynamics model and numeric dynamics model and numeric routine to compute motionroutine to compute motion
Got its start in engineeringGot its start in engineeringsimulation and roboticssimulation and robotics
2
Forward Dynamics vs. Inverse DynamicsForward Dynamics vs. Inverse Dynamics
force andforce andtorquetorque
acceleration,acceleration,velocityvelocity
forwardforward
inverseinverse
Forward: given forces and torques, computeForward: given forces and torques, computeacceleration, velocity, and finally positionacceleration, velocity, and finally position
Inverse: given motion (positions), compute theInverse: given motion (positions), compute theforces and torques forces and torques
Why use forward dynamics?Why use forward dynamics?
Captures realistic movements because it isCaptures realistic movements because it isbased on physical constraintsbased on physical constraints
Can provide highCan provide high--level control over level control over animationanimation
Can allow principled methods for animatedCan allow principled methods for animatedelements to communicate elements to communicate –– leading toleading torich simulated worldsrich simulated worlds
AKA: initial value problemAKA: initial value problem
3
Types of simulationsTypes of simulations
PassivePassiveParticle systemsParticle systems
Spring/Mass systems Spring/Mass systems
Rigid bodiesRigid bodies
ActiveActiveArticulated rigid bodies Articulated rigid bodies -- linkageslinkages
Passive Passive vsvs Active dynamicsActive dynamics
model ofdynamics
integrator
graphics
control
userinputs
model ofdynamics
integrator
graphicsuser
inputs
PassivePassive
Active Active
4
Maya, etc support passive dynamics Maya, etc support passive dynamics Particles, deformations (cloth), rigid bodiesParticles, deformations (cloth), rigid bodiesGravity, collisions, frictionGravity, collisions, friction
SpringSpring--mass systemsmass systems
2D meshes = cloth2D meshes = cloth3D meshes = 3D meshes = jello,blobsjello,blobs
5
Particle (Mass) SystemParticle (Mass) System
F(tF(t) = ma) = ma
xx’’’’ = = F(t)/mF(t)/m -- One second order equationOne second order equation
mtF
tv
tv
tx
dt
dY
dt
d
/)(
)(
)(
)(
or:or:
vv’’ = = F(t)/mF(t)/m -- Two first order equations Two first order equations
xx’’ = v= v
Particle (Mass) SystemParticle (Mass) System
Use Euler Integration to update:Use Euler Integration to update:
1) Find New Velocity:1) Find New Velocity:
2) Find New Position:2) Find New Position: tttvtxttx )()()(
tm
tFtvttv
)()()(
6
Gravity(mg)
Particle (mass) systemParticle (mass) system
Gravity
External Force
Particle (mass) systemParticle (mass) system
7
Differential equation Differential equation –– visual reviewvisual review
),( txfx
x(tx(t): a moving point): a moving pointf(x,tf(x,t): ): xx’’ss velocityvelocity
Vector fieldVector field
The differential equationThe differential equation
defines a vector fielddefines a vector fieldover xover x
),( txfx
8
Initial value problemInitial value problem
Given the starting point,Given the starting point,follow the integral curvefollow the integral curve
Euler integrationEuler integration
),()()( txtftxttx
Simplest numerical solution methodSimplest numerical solution methodDiscrete time stepsDiscrete time stepsBigger steps, bigger errorsBigger steps, bigger errors
9
InaccuracyInaccuracy
Error turns this Error turns this x(tx(t), ), a circle into different a circle into different spirals defined by spirals defined by step sizestep size
InaccuracyInaccuracy
Inaccuracy can lead to Inaccuracy can lead to instabilityinstability
10
Midpoint methodMidpoint method
a)a) Compute a Compute a ““fullfull”” Euler stepEuler step
b) Evaluate f at midpoint, b) Evaluate f at midpoint, ffmidmid
c) Take a step from the original pointc) Take a step from the original pointusing the midpoint f value: using the midpoint f value:
midtftxttx )()(
Approximation of Taylor SeriesApproximation of Taylor Series
Fourth Order Fourth Order –– RungaRunga--KuttaKutta IntegrationIntegration
Many kinds of integratorsMany kinds of integrators
11
Many kinds of integratorsMany kinds of integrators
Adaptive Steps Adaptive Steps
Take a full step and two half steps from starting Take a full step and two half steps from starting pointpoint
Compare resultsCompare results
If difference is greater than threshold, then reduce If difference is greater than threshold, then reduce time steptime step
Else, possibly increase time stepElse, possibly increase time step
xx00(t)(t)
vv00(t)(t)
Particle PhysicsParticle Physics
xx11(t)(t)
vv11(t)(t)
YY00(t)(t) YY11(t)(t)ODE SolverODE Solver
mtF
tv
tv
tx
dt
dY
dt
d
/)(
)(
)(
)(
void void dydtdydt (double t, double* y, double *(double t, double* y, double *ydotydot))
12
What is different about rigid body motion?What is different about rigid body motion?
positionposition,,velocityvelocityrotationrotationangular velocityangular velocity
Also, in addition to mass, Also, in addition to mass, mm, , and rotational inertia, and rotational inertia, II
iFtF )(
Net forceNet force
x(tx(t))
v(tv(t))
FF11FF22
FF33
13
?
)(
?
)(
tF
tv
Yx(tx(t))
v(tv(t))
Body StateBody State
?
)(
?
)(
?
)(
?
)(
tF
tv
tMv
tx
dt
dY
dt
d
Rigid Body Equation of MotionRigid Body Equation of Motion
14
How does a point move on the surface of the body?How does a point move on the surface of the body?
p(tp(t))
OrientationOrientation
Lets represent orientation as a rotation matrix, Lets represent orientation as a rotation matrix, R(tR(t))
Points move in world space due to rotation:Points move in world space due to rotation:
OrientationOrientation
(Actually, we use (Actually, we use quaternionsquaternions))
)()()( txptRtp o
15
Lets represent angular velocity as a vector Lets represent angular velocity as a vector (t(t))which is both spin direction and speedwhich is both spin direction and speed
Orientation changeOrientation change
How are How are R(tR(t)) and and (t(t)) related?related?
(t(t))
)(
0)()(
)(0)(
)()(0
)( tR
tt
tt
tt
tRdt
d
xy
xz
yz
Angular VelocityAngular Velocity
**(t)(t) will be shorthand for this matrixwill be shorthand for this matrix
Change inChange in R(tR(t)) due to due to (t(t)) is specified as:is specified as:
16
Need to relate Need to relate (t(t)) and and massmass to to F(tF(t))
?
)(
)()(
)(
)(
)(
)(
)(*
tF
tRt
tv
t
tMv
tR
tx
dt
dY
dt
d
Rigid Body Equation of MotionRigid Body Equation of Motion
Inertia TensorInertia Tensor
IzzIzyIzx
IyzIyyIyx
IxzIxyIxx
tI )(
Relate angular velocity derivative and mass Relate angular velocity derivative and mass distributiondistribution
17
?
)(
?
)(
?
)(
?
)(
tF
tv
tMv
tx
dt
dY
dt
d
Rigid Body Equation of MotionRigid Body Equation of Motion
?
)(
)()(
)(
)()(
)(
)(
)(*
tF
tRt
tv
ttI
tMv
tR
tx
dt
dY
dt
d
Rigid Body Equation of MotionRigid Body Equation of Motion
18
Rigid Body Equation of MotionRigid Body Equation of Motion
)(
)(
)()(
)(
)()(
)(
)(
)(*
t
tF
tRt
tv
ttI
tMv
tR
tx
dt
dY
dt
d
iFtF )(
Net forceNet force
x(tx(t))
v(tv(t))
FF11FF22
FF33
19
Net torqueNet torque
x(tx(t))
FF11FF22
FF33
ii Ftxpt ))(()(
pp11
pp22
pp33
A few notes on the Inertia TensorA few notes on the Inertia Tensor……
IzzIzyIzx
IyzIyyIyx
IxzIxyIxx
tI )(
20
dmdm
r = moment armr = moment arm
dmrI 2
Computing InertiaComputing Inertia
ParallelParallel--AxisAxis
Ix = Iy = 1/12 m (3r2 + l2)
Iz = mr2/2
I = Io + md2
d
Computing InertiaComputing Inertia
21
Approximating Approximating IIbodybody –– Point SamplingPoint Sampling
Pros: Simple, fairly accuratePros: Simple, fairly accurateCons: Expensive, requires volume testCons: Expensive, requires volume test
Inertia tensor varies in world space,Inertia tensor varies in world space,but not in body spacebut not in body space
22
Rigid Body Equations of MotionRigid Body Equations of Motion
)(
)(
)()(
)(
)()(
)(
)(
)(*
t
tF
tRt
tv
ttI
tMv
tR
tx
dt
dY
dt
d
)(
)(
)()(
)(
)()(
)(
)(
)(*
t
tF
tRt
tv
ttI
tMv
tR
tx
dt
dY
dt
d
Rigid Body Equations of MotionRigid Body Equations of Motion
L(tL(t) ) –– linear momentumlinear momentumH(tH(t) ) –– angular momentumangular momentum
23
Additional forcesAdditional forces
Gravitational forcesGravitational forces
Wind/air resistanceWind/air resistance
Collisions/impactsCollisions/impacts
FrictionFrictionSliding Sliding –– box on planebox on planeRolling Rolling -- wheel wheel
Forces for collision responseForces for collision response
24
Articulated rigid bodies Articulated rigid bodies
Linked chain of bodies, Linked chain of bodies,
Possibly branchingPossibly branching
Joint types:Joint types:Slider, telescopingSlider, telescopingHingeHingeUniversal JointUniversal JointGimbalGimbalBall and socketBall and socket
Equations of motion often computed Equations of motion often computed automatically (commercial solvers)automatically (commercial solvers)
No control = rag dollNo control = rag doll
Must provide control Must provide control
Articulated rigid bodies Articulated rigid bodies
25