Post on 27-Dec-2015
Chap 7Physically Based Animation
1Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Physically Based Animation
Forces are typically used to maintain relationships among geometric elements Accuracy vs. physical realism
Animators is not necessarily concerned with being accurate but rather with believabibity
Some forces may not relate to physics at all They may model constraints that an animator may wish
to enforce on the motion
CS Dept., NCTU, J. H. Chuang2Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Physically Based Animation
When modeling motion using physics principles, we need to decide the level at which to model the process Procedure
Computationally less expensive, easier to program Lacks flexibility
Purely physics Computationally expensive More flexible
CS Dept., NCTU, J. H. Chuang3Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Physically Based Animation
When physical models are used, animator is relieved of lower level specification of motions Needs to be concerned with specifying high-level
relationships or qualities of the motion
CS Dept., NCTU, J. H. Chuang4Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Outline
Basic physics Spring meshes Particle systems Rigid body simulation Enforcing soft and hard constraints
A Good reference: Read Witkin and Baraff’s SIGGRAPH’01 course notes:
Physics-based modeling at http://www.pixar.com/companyinfo/research/pbm2001/index.html
CS Dept., NCTU, J. H. Chuang5Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Basic physics
Newton’s laws of motions
CS Dept., NCTU, J. H. Chuang6
221
)'(2
1'
'
d
mmGf
tvvpp
tavvm
fa
maf
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Basic physics
CS Dept., NCTU, J. H. Chuang7
mv
vkf
vkf
LLkf
vv
sdd
restcurrentss
:Momentum
air assuch medium, aough thr
velocity resists damper, similar to :Viscosity
:length spring theof velocity the toalproportion
negatively isbut spring, a like :forceDamper
( :force Spring )
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Basic physics
CS Dept., NCTU, J. H. Chuang8
I
center smass' itsabout mass ofon distributi sobject'
describing Imatrix 3x3 a n;orientatioin change to
resistance sobject'an of measure a :inertia ofmoment
onacceleratiangular
locityangular ve
force rotational :Torque
Fr
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Spring meshes
Flexible objects Flexibility is modeled by a spring-mass-damper
simulation simulating the reaction of the body to external forces.
Each vertex: a point mass Assigned by animators Evenly distributed among object’s vertices
Each edge: a spring Rest length is original edge length
Spring constants Arbitrary, assigned uniformly throughout the object
CS Dept., NCTU, J. H. Chuang9Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Spring meshes
Spring-mass-damper simulation As external forces are applied to specific vertices
Vertices will be displaced relative to other vertices The displacement induces spring forces, which will impart
forces to the adjacent vertices and reactive forces back to initial vertices.
Force propagation one time step at a time
CS Dept., NCTU, J. H. Chuang10
sdrestcurrents vkLLkf )(
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Spring meshesA simple example
CS Dept., NCTU, J. H. Chuang11
Instant force F applied to V2.Length of springs E12 and E23 changes.Spring forces impart restoringforces to V1 and V2, and V2 and V3
Since external force is wrongly assumed constant throughoutthe time step, a spring simulation may numerically explode (the motions get larger and larger).
A smaller time step, or smallerspring constant, or larger massescan be used; but slow down the simulation.
A common method: add dampers.Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Spring meshesDampers
CS Dept., NCTU, J. H. Chuang12
A damper introduces an additional force in the spring that works against the velocity of the spring length, thus helping to limit the speed at which a spring changes length. Help to control the change in length and keep it
within some range that does not allow the simulation to explode.
sdrestcurrents vkLLkf )(Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Spring meshes
CS Dept., NCTU, J. H. Chuang13
Modeling with only object edges with spring dampers can result in a model that has more than one stable configuration. Additional spring dampers can help to stabilize the
shape.
If a cube’s edges are modeled with spring dampers, during applications of extreme external force is applied, the cube can turn Inside out.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Spring meshesAngular spring dampers
CS Dept., NCTU, J. H. Chuang14
angular spring resists deviation to the rest angle between faces and imparts a torque along the edge that attempts to restore the rest angle.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Spring meshesVirtual springs
CS Dept., NCTU, J. H. Chuang15
Virtual springs introduce forces into the system that do not directly model physical elements. For example, Example on the last page Virtual springs with zero rest lengths can be used
to constrained one object to lie on the other Virtual springs with non-zero rest lengths can be
used to maintain separation between moving objects.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Particle systems
Particles have been used to animate many behaviors, such as gases, water, fire, rubber, clothes, flocking, hair.
CS Dept., NCTU, J. H. Chuang16Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang17
Particle systemsAssumptions
Particles do not collide with other particles Particles do not cast shadow on each other,
except in an aggregate sense Particles only cast shadow on the rest of
environment Particles do not reflect light Particles often have a finite life span
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang18
Particle systemsSteps in a frame
Generate any new particles Each new particle is assigned attributes Any particles that have exceeded their life
span are terminated The remaining particles are animated and their
shading parameters changes according to the controlling process
The particles are rendered
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang19
Particle generation For each frame, particles are generated
according to a controlled stochastic process User-specified distribution centered at the desired
average number of particle per frame Can be function of time
factor. scale a is and 1.0, to1.0- from
number random a returns Rand() where
Rand() particle of #
r
rn
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang20
Particle attributes Particle properties:
mass position velocity force accumulator age, lifespan rendering properties (shape parameters, color,
transparency) Each of the attributes is initialized when the
particle is created.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang21
Particle life span
At each new frame, each particle’s lifetime is decremented by oneWhen the attribute reaches zero, the particle is removed from the system.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang22
Particle animation Each particle is animated throughout its life.
Includes position, velocity, and rendering attributes Position and velocity
Users consider forces and compute the resultant particle acceleration, update its velocity, and update the position.
Color and transparency can be a function of time, its own life span remaining, its height, and so on. Shape can be a function of its velocity
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang23
Particle animation Forces on particles
Forces can be unary, particle pair, or environmental. Unary forces
Gravity, viscous drag Particle pair forces
Can be represented by springs and dampers, if desired. Environmental forces
Arise from a particle’s relationship to the environment
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang24
Forces on particles
Particles respond to forces We represent this using differential equations
m
fx
2nd order ODEm
fv
vx
1st order ODEs
phase space
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang25
Unary Forces
Forces that only depend on one particle
Gravity Wind FieldsViscous Drag
fdrag
v
f = mg f = kvwindf = -kdv
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang26
n-ary Forces
Forces that depend on n particles Example: binary forces between two particles
- spring and damper
Springs
||)|(| 0
ba
babasa lk
xx
xxxxf
||||
)()(
ba
ba
ba
babadk
xx
xx
xx
xxvv
af
bf
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang27
n-ary Forces: Spring Force If particle is located farther than the rest position, the
spring force needs to pull it back
If the particle is located nearer than the rest position, the spring force needs to push it away
Combine two cases:
0 rxx ba
0 , klkfa
0 rxx ba
0 , klkfa
0 ,)( sbasa klrxxkf
ba
babas xx
xxrxxk
)(
bx
ax
ba
ba
xx
xxl
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang28
n-ary Forces: Damping Forces
According to the law of energy conservation, a particle system consists of only masses and springs keep bouncing from each other after external forces disappear
Damping/viscous drag force resist motion, making a particle system gradually come to rest in the absence of external forces
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang29
n-ary Forces: Damping Forces (cont.)
It is highly recommended that at least a small amount of damping is applied to each particle
Excessive damping, however, makes a particle appear that floating in molasses (energy dissipates out too quickly, not responsive)
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang30
n-ary Forces: Damper Force If two particles are departing, the damper force needs
to pull them back
If two particles are approaching, the damper force needs to push them away
Combine two cases:
0)( lvv ba
0 , klkfa
0 ,)( dbada kllvvkf
ba
ba
ba
babad xx
xx
xx
xxvvk
)()()(
0)( lvv ba
0 , klkfa
bvav
ba
ba
xx
xxl
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang31
Spatial Forces
Forces that depend on nearby particles within a local region
Gravity, Lennard-Jones and electric potentials
Spatial data structures can optimize computations
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang32
Particle rendering Several methods
Model each particle as a point light source Each particle is rendered to a small graphical primitive
(blob). Particles that map to the same pixels in the image are
additive - the color of a pixel is simply the sum of the color values of all the particles that map to it
Model each particle as a textured billboard Polygon facing the viewer, texture
Rendered as Metaballs in off-line rendering; isosurfaces computed from particle-metaballs make quite convincing liquids.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang33
Particle renderingParticle
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang34
Particle renderingParticle
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang35
Particle rendering Billboard texture
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang36
Particle rendering Billboard texture
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang37
Particle rendering Billboard texture
From Mark Harris’s workhttp://www.markmark.net/clouds/
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Particle renderingBillboard texture
An impostor replaces a cloud with a billboard textured with an image of the cloud from a certain viewpoint. Image is updated only when translation of the
viewpoint introduces enough error in the image Impostors can be reused for many frames.
By using impostors, we are able to render cloudy scenes of hundreds of clouds and hundreds of thousands of particles at very high frame rates.
CS Dept., NCTU, J. H. Chuang38Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Particle renderingBillboard texture
CS Dept., NCTU, J. H. Chuang39
Figure 6: Impostor generation and translation errormetric.
Impostor generation and translation error metric
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang40
Particle rendering
VideoCloud rendering by Niniane Wanghttp://www.ofb.net/~niniane/clouds/
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang41
Particle renderingMetaballs and isosurface
From “Screen Space Fluid Rendering with Curvature Flow “http://industrialarithmetic.blogspot.com/2009/01/
our-paper-screen-space-fluid-rendering.htmlAnimation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang42
Collision Detection
Determine when a particle has collided an object
Particle has collided if and only if
N
0xN
0xN
0xN
Object’s surface
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang43
Collision Response
What should we do when a particle has collided?
The correct thing to do is rollback the simulation to the exact point of contact
Easier to just modify positions and velocities
nv
tv
vN
newv
After the collision:
tnnew vvv
coefficient of restitution
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang44
Contact Forces
When the particle is on the collision surface a contact force resists penetration
Contact forces do not resist leaving the surface
Simple friction can be modeled
ffNf )( c 0)( fN
0cf 0)( fN
tff vk )( fNf 0)( fN
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang45
Structure of Particle Systems Separate the data structures and integration
Particle Systemtimeparticles
Particle
Solver
derivativesstate
state/derivatives
statesend data as6n vectors
xvfm
xvfm
xvfm
xvfm
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang46
Structure of Particle SystemsImplementation
Solver Interface
xvfm
GetDim
Deriv Eval
Get/Set Statexv
vf/m
System Solver
6
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang47
Structure of Particle SystemsImplementation
Solver Interface
particlesGetDim
Deriv Eval
Get/Set Statex1
v1
v1
f1/m1
System Solver
6n
n time
x2
v2
v2
f2/m2
xn
vn
vn
fn/mn
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang48
Physics Engines for Dynamics Simulation
Open Dynamics Engine (ODE) Free software http://www.ode.org/ high performance library for simulating rigid body
dynamics. It is fully featured, stable, mature and platform
independent with an easy to use C/C++ API. It has advanced joint types and integrated collision
detection with friction. ODE is useful for simulating vehicles, objects in
virtual reality environments and virtual creatures.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang49
Physics Engines for Dynamics Simulation
Havok Commercial software “Reactor” in 3ds MAX State-of-the-art game physics solution, for use with
in-house game animation systems Havok Destruction™ is the cross-platform tool for
simulation of rigid body destruction.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang50
Physics Engines for Dynamics Simulation
NVIDIA PhysX A powerful physics engine which enables real-time
physics in leading edge PC and console games. Is widely adopted by over 150 games, is used by
more than 10,000 registered users. Designed specifically for hardware acceleration by
powerful processors with hundreds of cores. Combined with the tremendous parallel processing capability of the GPU, PhysX will provide an exponential increase in physics processing power
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang51
Physics Engines for Dynamics Simulation
AGEIA PhysX accelerator The world’s first dedicated physics processor designed
to support extreme physical gaming interactions. Its highly parallel, interactive PhysX cores are
optimized for dynamic, large-scale, physics processing to accelerate physical motion and interaction at a scale and quality far beyond that of general purpose processors.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Rigid Body Simulation
Various forces to be simulated are modeled. When the forces are applied to objects, they
induce linear acceleration (based on object’s mass) angular acceleration (based on mass’s distribution)
These accelerations are integrated over a delta time step to get changes of object’s velocities, which in turns integrated over a delta time step to produce changes in position and orientation.
CS Dept., NCTU, J. H. Chuang52Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Rigid Body Simulation
Various forces to be simulated are modeled. When the forces are applied to objects, they
induce linear acceleration (based on object’s mass) angular acceleration (based on mass’s distribution)
Read Witkin and Baraff’s SIGGRAPH’01 course notes: Physics-based modeling http://www.pixar.com/companyinfo/research/
pbm2001/index.html
CS Dept., NCTU, J. H. Chuang53Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Rigid Body SimulationUpdate cycle
CS Dept., NCTU, J. H. Chuang54Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Rigid Body Simulation
Continuous process vs. discrete time simulation Assume acceleration is constant over the delta time
step These accelerations are integrated over a delta time
step to get changes of object’s velocities, which in turns integrated over a delta time step to produce changes in position and orientation.
How to update? Euler integration method Runge –Kutta method: Second-order in magnitude of
error termCS Dept., NCTU, J. H. Chuang55Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang56
Physics-based Simulation
A procedure that generates a sequence of the states of a system based on physics laws
Newtonian lawselastic forces
windgravityfriction
…
xi
xi+1
△x
xixi+1= xi+ △x
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang57
Differential Equations
Differential equation describes the relation between an unknown function and its derivatives
Solving a differential equation is to find a function that satisfies the relation
Numerical solution of differential equations is based on finite-dimensional approximation
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
),())(( tftfdt
dxx
x
CS Dept., NCTU, J. H. Chuang58
Ordinary Differential Equations Ordinary differential equation (ODE)
All derivatives are with respect to single independent variable, usually representing time
Time derivative of the unknown function
Unknown function that evaluates the state given time
Known function
00 at time vector state:)( ttx*We’ll show that a higher ODE can be transformed into this 1st order system soon!
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang59
Higher-Order ODEs
Order of ODE determined by highest-order derivative of solution function appearing in ODE
Equations with higher derivatives can be transformed into equivalent first-order system
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang60
Higher-Order ODEs (cont.) Given k-th order ODE
Define Original ODE equivalent to first order system
),,',...,,( )2()1()(
tyyyyfdt
yd kkk
ytx )(1
')(2 ytx
")(3 ytx
)1()( kk ytx
),,',,('
'
'
'
)1(
3
2
1
2
1
tyyyf
x
x
x
x
x
x
x
kk
k
k
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang61
Visualizing Solution of ODE
x1
x2),( tfdt
dx
xx
point movinga :)(tx
s velocities':),( xx tf
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang62
Vector Field
The complete set of all solutions to the differential equation defines a vector field over (x, t) plane.
x1
x2
Think of this vector field as the sea, and the velocity of current at different places and time is defined by f(x,t)
),( tf xx
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang63
Initial Value Problem
For a particular initial value, the solution is a curve. Given the starting point, follow the integral curve
)( find ,)( and ),( Given 00 tttf xxxxx
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
x1
x2
Release a ball at any starting point and let it drift following the current. The trajectory swept out by the ball is an integral curve.
CS Dept., NCTU, J. H. Chuang64
Numerical Solution of ODEs Instead of true integral curve, numerical solution
follow a polygonal path Each leg is obtained by evaluating the derivative
at discrete time steps Bigger steps, bigger errors
x1
x2
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang65
Issue I: Inaccuracy
Error turns x(t) from a circle into the spiral of your choice! May jump to other circles
x1
x2
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang66
Issue II: Instability
May diverge!
x1
x2
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
to Neptune!
CS Dept., NCTU, J. H. Chuang67
Euler’s Method
Simplest numerical solution method Bigger time steps, bigger errors
x1
x2
),()()( tfhtht xxx
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
)(2
)()()(2
000 xxxx hththt
CS Dept., NCTU, J. H. Chuang68
Euler’s Method (cont.)
Solves ODE using one-term Taylor-series
O(h2): 2nd order accurate
),( tf xx
),()()( tfhtht xxx
)( 00 txx
nnn hxxx 1
)( find ,)( and ),( Given 00 tttf xxxxx
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang69
Euler’s Method (cont.)
Truncation error in s single step : O(h2) The error in a complete solution is an
accumulation of all the single step errors
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
)O( iserror totalSo
).O( oferror an acquires stepeach where
steps need we),( compute To
2
2
0
hh
T
h
T/hTt x
Rigid Body Simulation Euler integration method (Book)
Explicit Euler integration method
CS Dept., NCTU, J. H. Chuang70
),('1
1
nnnn
nn
yxhfyy
hxx
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang71
Drawbacks of Euler’s Method
Too inaccurate to be used in practice Inefficiency
Need to use small time-steps to avoid divergence Example:
http://www.cse.uiuc.edu/iem/ode/eulrmthd/
Improvement using the midpoint method Slope at midpoint is used
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang72
Runge-Kutta methodThe Midpoint Method
a. Compute an Euler step
b. Evaluate f at the midpoint
c. Take a step using the midpoint value
))(( 0tfh xx
2
))(()(
)2
)((
00
0
tfhtf
tffmid
xx
xx
midfhtht )()( 00 xxAnimation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
x1
x2
Assume f depends on t only indirectly through x
CS Dept., NCTU, J. H. Chuang73
Runge-Kutta method The Midpoint Method (cont.)
Solves ODE using two-term Taylor-series
Approximating f by Taylor-series
)(3
)(2
)()()(3
0
2
000 xxxxx ht
hththt
)()(')('),( xxx
xxxx ffdt
dftf
dt
d
dt
d
)(' )()( 000 xxxxx fff
00 2)( xx h
f )(')(2
)())(2
( 00000 xxxxx ffh
ffh
f
)(2
where 0xx fh
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang74
Runge-Kutta method The Midpoint Method (cont.)
)(3
)(2
)()()(3
0
2
000 xxxxx ht
hththt
0000 2)())(
2( xxxx h
ffh
f
)())(
2(
2 0000
2
xxxx ffh
fhh
)()())(2
()()( 300000 hOff
hfhhft
xxxxx
)())(2
()( 3000 hOf
hhft xxx
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Turning O(h2) to O(h3)
Runge-Kutta method The Midpoint Method (Book)
Runge –Kutta method Symmetric w.r.t. the time interval Second-order in magnitude of error term
CS Dept., NCTU, J. H. Chuang75
method.Euler explicit using evaluated is
interval of middle at the derivative the: thatNote
)),(2
,2
( ''1
1
nnnnnn
nn
yxfh
yh
xhfyy
hxx
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang76
Runge-Kutta 4th Order Method
Using a weighted average of slopes obtained at four points
),( 00 tf x
)2
,2
( 01
0
ht
kf x
t
)2
,2
( 01
0
ht
kf x
),( 030 htkf xx
)( 0 ht x
)()22(6
1)()( 5
432100 hOkkkktht xx
),( 001 thfk x
)2
,2
( 01
02
ht
khfk x
)2
,2
( 02
03
ht
khfk x
),( 0304 htkhfk x
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Runge-Kutta 4th Order Method (Book)
Fourth-order Runge –Kutta method
CS Dept., NCTU, J. H. Chuang77
)(226
1
),(
)2
,2
(
)2
,2
(
),(
543211
3'
4
2'3
1'2
'1
1
hOkkkkyy
kyhxhfk
ky
hxhfk
ky
hxhfk
yxhfk
hxx
nn
nn
nn
nn
nn
nn
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang78
)(6336
),(
)2
,2
(
)2
,2
(
),(
543211
3'
4
2'3
1'2
'1
1
hOkkkk
yy
kyhxhfk
ky
hxhfk
ky
hxhfk
yxhfk
hxx
nn
nn
nn
nn
nn
nn
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang79
Adaptive Step Size
Ideally, we want to choose h as large as possible, but not so large as to cause big error or instability
We can vary h as we march forward in time
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
What is optimal h if we want to have an error of as much as ε, and the current error is e?
Adaptive Step Size for Euler’s Method
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang81
ek
ekek
h
h'e
khh'
he
222)(
.Let *
CS Dept., NCTU, J. H. Chuang82
Take Home Message
Don’t use Euler’s method Inaccuracy Inefficiency (or unstable)
Do use adaptive step size
Read Witkin and Baraff’s SIGGRAPH’01 course notes: Physics-based modeling http://www.pixar.com/companyinfo/research/
pbm2001/index.html
x1
x2
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Motion equation for a rigid body
To develop the equations of motion for a rigid body, we need to discuss Linear force vs. rotational force
Torque Linear momentum vs. angular momentum Inertia tensor Equations
CS Dept., NCTU, J. H. Chuang83Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Orientation and rotational movement angular velocity
Angular velocity w(t) Direction: Axis of rotation, Speed of orientation in revolutions per unit of time
For linear motion, x(t) and v(t) are related by
How are R(t) and w(t) related? We need to find how the derivative of a vector in a
rigid body is related to w(t)
CS Dept., NCTU, J. H. Chuang84Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
)()( txdt
dtv
Orientation and rotational movement angular velocity of a particle
Angular velocity of a point
CS Dept., NCTU, J. H. Chuang85
sin)()()(
)()()(
)( oflocity angular ve)(
space. in world represnted is )(
)()()(
trtwtr
trtwtr
tptw
tr
trtxtp
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
p
Orientation and rotational movement angular velocity of a particle
CS Dept., NCTU, J. H. Chuang86Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
)()()(
can write we together, thisPutting .)(
magnitude has )( of change ousinstantane theand
, )( and both lar toperpendicu is )( of change
ousinstantane theSo axis. )( on the centered circle a
out tracesa"" then constant, islocity angular ve Suppose
).( lar toperpendicu is )(
and )( toparallel is )( where),()()( Write
?)()()(Why
trtwtr
twb
tr
twbtr
tw
twtb
twtatbtatr
trtwtr
Orientation and rotational movement angular velocity of a particle
CS Dept., NCTU, J. H. Chuang87Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
)()()( ofDirection
:Note
)()(
)()()(
))(()(
)()()(
)( toparallel is where
,)()(Let
trtwtr
tbtw
tbtwatw
tbatw
trtwtr
twa
tbatr
Orientation and rotational movement angular velocity of a rigid body
Angular velocity of a rigid body Position and orientation of a rigid body are
represented by x(t), and R(t) x(t), and R(t) are used to transform the body-space
description into world space
CS Dept., NCTU, J. H. Chuang88Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Orientation and rotational movement angular velocity of a rigid body
R(t) specifies a rotation of the body about the center of mass It is a matrix of 3 orthogonal column vectors At time t,
represents the x-axis of body space in world space
Each column vector represents a vector from the origin
A point Q on the rigid body with local coordinate q
CS Dept., NCTU, J. H. Chuang89Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
)()()()( where),(
0
0
1
)( 3211 tRtRtRtRtRtR
Orientation and rotational movement angular velocity of a rigid body
CS Dept., NCTU, J. H. Chuang90Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Orientation and rotational movement angular velocity of a rigid body
At time t, the derivative of the first column of R(t) is the rate of change of this vector. So
CS Dept., NCTU, J. H. Chuang91
)()()()()()()(
)()()()(
321
321
tRtwtRtwtRtwtR
tRtRtRtR
)())()(()()()()()()(
)()()(
tvtxtqtwtvqtRtxqtRtq
txqtRtq
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
ba
b
b
b
aa
aa
aa
abba
abba
abba
ba
tRtwtRtwtw
tRtw
tRtwtRtwtRtwtR
z
y
x
xy
xz
yz
yxyx
zxzx
zyzy
ii
*
**
*
321
0
0
0
:Note
).()()()(such that matrix theis )( where
)()(
)()()()()()()(
Orientation and rotational movement angular velocity of a rigid body
A point Q on the rigid body with body-space coordinate q. Then the world-space location of q(t) is the result of
first rotating q about the origin and then translating it:
CS Dept., NCTU, J. H. Chuang92
)())()(()()())()(()(
)())()()(()()(
)()(
)()()(
:)( of velocity theand
)()()(
*
1*
tvtxtqtwtvtxtqtw
tvtxtqtRtRtw
tvqtR
txqtRtq
tq
txqtRtq
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
This separates the velocity of a point on a rigid body into two components:A linear component v(t)A angular component w x (q(t)-x(t))
Orientation and rotational movementCenter of mass
Integration of the differential mass times its global position in the object
CS Dept., NCTU, J. H. Chuang93
M
tqmtx
mM
ii
i
)()(
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Orientation and rotational movementForces and torque
Linear force vs. rotational force
CS Dept., NCTU, J. H. Chuang94
)())()(()(
where
)()(
)()(
tFtxtqt
tt
tFtF
iii
i
i
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Orientation and rotational movementLinear momentum
Linear momentum p of a particle with mass m and velocity v:
Linear momentum of a rigid body
CS Dept., NCTU, J. H. Chuang95Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
)(
)(
))()(()()(
))()(()()(
)()(
tvM
tvm
txtrmtwtvm
txtrtwmtvm
trmtP
i
iii
iii
ii
)()( tmvtP
Total linear momentum of a rigid bodyis the same as if the body is simply aparticle with mass m and velocity v(t).
Orientation and rotational movement Linear momentum
Derivative of linear momentum and force
Instead of v(t), we use P(t) as a state variable for the rigid body. Be more consistent with the way we deal with
angular velocity and acceleration.
CS Dept., NCTU, J. H. Chuang96
)()()()(
:constant is
tFtmatvmtP
M
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Orientation and rotational movementAngular momentum (book)_
Angular momentum of a particle
CS Dept., NCTU, J. H. Chuang97Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
)()()(
is
momentumangular its ,)( velocity and , mass
,)( vector local with object, on the particle aFor
trmtrtL
trm
tr
Orientation and rotational movement Angular momentum (book)
Angular momentum of an object
CS Dept., NCTU, J. H. Chuang98
)()(
})])()(())([({
})])(()([))({
}))]()(()([))({
))()(())()((
)()()(
:object theof momentumangular Total
ttL
qtRtwqtRm
qtRtwmqtR
txtqtwmqtR
tvtqmtxtq
trmtrtL
i
i
ii
iii
iii
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Orientation and rotational movementAngular momentum
Angular momentum of a rigid body Similar to linear momentum
where I(t) (called inertia tensor) is a 3x3 matrix that describe how the mass in the body is distributed relative to the body’s center of mass.
I(t) depends on orientation of the body; but does not depend on the body’s translation
CS Dept., NCTU, J. H. Chuang99Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
)( )()( twtItL
Orientation and rotational movementInertia tensor
At a given time t, let be the displacement of particle i from body’s mass center x(t) by
.
I(t) is expressed in terms of r’i as the symmetric matrix
CS Dept., NCTU, J. H. Chuang100Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
)()()(' txtrtri
)(' tri
Orientation and rotational movementInertia tensor
How to compute I(t) for a rotated dody? Compute at run-time? Too expensive! Pre-computed I(t) in body-space coordinates and
then compute it at run time after rotation.
CS Dept., NCTU, J. H. Chuang101Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Tbody tRtItRtI )()()()(
Orientation and rotational movementInertia tensor
CS Dept., NCTU, J. H. Chuang102Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
asrewritten becan )( , Using2,2,2,,, tIrrrrr iziyixi
T
i
:itself with ofproduct outer theTaking ,ir
Orientation and rotational movementInertia tensor
CS Dept., NCTU, J. H. Chuang103Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
asrewritten becan )(tI
,)()( and )()( where)()()( Since 0,
0 ItRtRrtRtrtxrtRtr Tiiii
Orientation and rotational movementInertia tensor
CS Dept., NCTU, J. H. Chuang104Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
as )( rearrangecan wescalar, a is Since 00 tIrr iTi
Let
We have
Constant over the simulation
Orientation and rotational movementInertia tensor
CS Dept., NCTU, J. H. Chuang105Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Orientation and rotational movementInertia tensor
Linear momentum and linear velocity
Angular momentum and angular velocity
I(t): inertia tensor, describes how the mass is distributed about the center of mass in space
For an un-transformed object: Iobject
For a transformed object (depends only on orientation)
CS Dept., NCTU, J. H. Chuang106
)( )( tvMtP
)( )()( twtItL
Tobject tRtItRtI )()()()(
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Motion Equation
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang107
The state of a rigid body Spatial information
Position Orientation
Velocity information Linear momentum Angular momentum
Known information Mass Body-space inertia
Motion Equation
CS Dept., NCTU, J. H. Chuang108
)()()(
)()()(
)()(
)(
)(
)(*)(
)(
)(
)(
)(
)(
)(
)(
)(
)(
)(
)(
1 tLtItw
tRItRtI
M
tPtv
t
tF
tRtw
tv
tL
tP
tR
tx
dt
dtS
dt
d
tL
tP
tR
tx
tS
Tbody
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Bodies in collision
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang109
Objects moving in a dynamic scene Objects in collision – need to do the detection Objects sliding against on other object Objects resting on each other
Need to calculate forces for computing accurate reaction
Ultimate goal in VR Real and virtual objects need to behave like real
ones. At a minimum
Objects should not pass through each other, and things should move as expected when pushed, pulled, or grasped.
Overall Physical simulation in VR must run reliably,
seamlessly, automatically, and in real time.
Bodies in collision
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
111
Collision detectionComputer Animation
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
112
Collision detectionHaptic Interaction
From J.C. Latombe’s notes
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
113
Collision detectionMotion/Path Planning
From James Kuffner
From J.C. Latombe
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
114
Collision detectionCrowd Simulation
From J.C. Latombe’s notes
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
To prevent interpenetration Collisions must be detected. Velocities must be adjusted in response to
collisions. Collision response must be computed.
If the collision response does not cause the objects to separate immediately, contact forces must be calculated and applied until separation finally occurs.
Bodies in collision
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
A naive collision detection has Fixed-timestamp weakness All-pair weakness Pair-processing weakness
Features that current methods have Interactive rate Handle polygon soaps Models can undergo rigid-body motion Provide well-fit bounding volume Collision detection only occurs at discrete times.
Problems of Collision Detection
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
All-pair weakness If the scenario contains n moving objects and m
static objects, total object test for each frame is
Pair processing weakness Note:
Performance evaluations for collision detection are extremely difficult since algorithms are sensitive to the actual scenarios, and there is no algorithm that performs best in all cases.
Performance of a naive method
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
2
nnm
Bounding volume for object level and polygon level. Pure bounding volume Hierarchical bounding volumes
Support progressive collision detection.
Spatial coherence Usually large regions of the space are occupied by only one object or
none at all. If some objects share the same region, they are likely intersecting.
Time coherence Moving objects usually move on a continuous path. Results of earlier
collision query can be exploited.
Speed Up Methods
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Two-level Collision Detection
Globally searching pairs of objects that have
potential collision Spatial partition
Dimension reduction and sorting (Sweep-and-Prune) Collision detection on a pair of objects
Hierarchical CD based on OBBTree, AABBTree,… Polygon-polygon overlap test
Two-level Collision Detection
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang119 119
CS Dept., NCTU, J. H. Chuang
Two-level CD system
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Simulation
Collision response
Pruning Multi-Body pairs(Sweep/Prune)
Exact collisionDetection (OBB tree)
Spatial coherence is usually exploited by partitioning the space. All-pair weakness can be resolved by the use of
spatial coherence. Space partition methods differ in fast neighbor-
finding (for static environments) and fast updating for moving objects. Grid (uniform partition) Octree Binary space partition
Space Partition
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Sorting objects in 3-D space by dimension reduction If two objects collide in a 3D space, their orthogonal
projections onto the xy, yz, and xz-planes and x, y, and z-axes must overlap.
Project bounding volume of objects. Based on Axis-aligned bounding boxes (AABB).
Fixed-size bounding cube: large enough to contain the object at any orientation.
Dynamically-resized rectangular bounding boxes
Temporal Coherence One or Two-Dimension Sweep and Prune
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Project each 3D box onto x, y, and z axes. Construct 3 lists, one for each dimension.
Each list contains the values of the endpoints of the projected interval corresponding to that dimension.
Determine which intervals overlap by sorting these lists. Utilize temporal or frame coherence by changing
only the values of the interval endpoints. Bubble sort or insertion sort work well for
previously sorted lists.
One or Two-Dimension Sweep and Prune
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Fixed-sized cubes are preferred over dynamically-resized boxes, except for the class of oblong objects.
Which sorting method is better? Bubble sort works better for environments where
only a few objects move, such as walkthrough Insertion sort works better for environments where
large number of objects move. Overlap status consists of a Boolean flag for
each dimension. Whenever all three of these flags are set, the bb of objects pair overlap.
One or Two-Dimension Sweep and Prune Implementation issues - -1
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Bounding volume is used to do a pre-check before doing any further collision detection. Bounding sphere (BS)
Fast overlapping check, not a tight fit. Axis-aligned bounding box (AABB)
Fast overlapping check, a better tight fit. Oriented bounding box (OBB) Tight fit,
but with relatively expensive overlapping test. K-DOPS (direct oriented polytopes)
OBB + more cutting axes
Bounding Volumes
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
CS Dept., NCTU, J. H. Chuang
Bounding Volumes
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Hierarchical bounding volume is useful For efficiently resolving the pair-processing
weakness, and Providing a basis for the hierarchical or time-
critical scheme for collision detection. Three types:
Hierarchical Axis-aligned bounding box Hierarchical Oriented bounding box Hierarchical Bounding sphere
Hierarchical Bounding Volumes
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Common denominators of these schemes A hierarchical bounding volume is built for each
object. High-level code for a collision query is similar,
regardless of the BV type used. BV-BV overlapping tests and primitive-primitive
overlapping tests are different depending on what BVs and primitives are used.
A simple cost function can be used to trim, evaluate, and compare performance.
General Hierarchical Collision Detection Scheme
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Common hierarchy used: K-ary tree, where each node may at most have k
children. At each internal node, there is a BV enclosing all its
children. At each leaf, there are one or more primitives.
Three ways of building a hierarchy Bottom-up Incremental tree insertion Top-down
Hierarchical Collision Detection Hierarchy Building
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Start Starts by combining a number of primitives and
finding a BV for them. Grouping
This BV is grouped with one or more BVs constructed in a similar way, thus yielding a new, larger parent BV.
Recursive grouping Repeat the grouping until only one BV exists,
which becomes the root of the hierarchy.
Hierarchical Collision Detection Bottom-
up Hierarchy Building
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Start with an empty tree All other primitives and their BVs are added one at a time to
the tree. To make an efficient tree, an insertion point should be selected so that
the total tree volume increase is minimized.
Little is known about this scheme in the context of collision detection.
Hierarchical Collision Detection Hierarchy Building by Incremental tree-insertion
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Start Find a BV for all primitives of the object, which is then acts as the root
of the hierarchy.
Recursively apply a divide-and-conquer strategy First to split the BV into k or fewer parts and find all included
primitives for each such part. A BV is then created for each part.
Potential advantage A hierarchy can be created on an as-needed basis, i.e., we can construct
the hierarchy for those parts of the object where it is actually needed. Used by majority of hierarchical CD.
Hierarchical Collision Detection Top-Down Hierarchy Building
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
K-ary tree K =2 minimizes the work to be done when
traversing a path from root to the worst-case leaf, and it is easier to compute the hierarchy than the case of higher k.
Higher k gives a tree with lower height, but it requires more work at each node.
Hierarchical Collision Detection
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Challenges Find tight-fitting bounding volume. Find hierarchy construction that creat balanced and
efficient tree. Efficient BV-BV overlapping test. Efficient primitive-primitive overlapping test.
Notes Balanced trees are expected to perform best in all cases,
since the time of CD query will not vary. But, it does not mean that it is best for all inputs, e.g.,
those parts that seldom or never be queried for a collision can be located deep in the hierarchy.
Hierarchical Collision Detection
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Collision detection Test whether or not two objects collide, and may
terminate whenever a pair of triangles has been found to be overlapping.
Collision determination In some cases, all pairs of overlapping triangles
might be wanted. Can be solved with small alterations of the code
for collision detection.
Hierarchical Collision DetectionCollision testing between Hierarchies -1
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
FindFirstHitCD(A, B) return({TRUE, FALSE});
if (not-overlap(ABV, BBV) return FALSE; else if(isLeaf(A)) /* try to reduce tested pairs */ if(isLeaf(B))
for each triangle pair TA in AC and TB in BC
if(overlap(TA, TB)) return TRUE;
else for each child CB in BC
FindFirstHitCD(A, CB)
else for each child CA in AC
FindFirstHitCD(CA, B) return FALSE;
Hierarchical Collision DetectionCollision testing between Hierarchies -2
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
CS Dept., NCTU, J. H. Chuang
Hierarchical Collision DetectionCost function -1
Cost function
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
BV a updatingfor cost :
time)-runat resized is BV the(if
motion smodel' todue updated BVs ofnumber :
testoverlap primitiveprimitive ofcost :
testsoverlap primitiveprimitive ofnumber :
testoverlap BVBV ofcost :
testsoverlap BVBV ofnumber :
where
u
u
p
p
v
v
uuppvv
c
n
-c
-n
-c
-n
cncncnt
Conflicting goals Creating a better hierarchical representation results
in lower values of nv, np, and nu. Creating better methods for BV-BV or primitive-
primitive tests would lower cv, cp. Bounding volume examples
Sphere, AABB, OBB K-DOPS (direct oriented polytopes) Pie slices Spherical shells: good fits for Bezier surfaces
Hierarchical Collision DetectionCost function -2
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Why OBBTree? Sphere tree and AABBTree do very well in
performing rejection tests, whenever two objects are far apart; but do poorly for objects in close proximity and having multiple contacts.
OBBTree was designed to perform especially well if parallel close proximity is found during collision detection.
Parallel close proximity: Two surfaces are very close and nearly parallel.
A fast overlapping test for OBB-OBB is provided.
Hierarchical OBBTree
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Collision detection based on OBBTree Preprocessing
Building an OBBTree for each object. Top-down Bottom-up
Detection computation Perform recursively the separating-plane test for
each pair of objects.
Hierarchical OBBTree
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Split the polygon soap along the longest axis of the OBB.
Pass through the OBB’s center OBBTree may not balanced. If the split fails, the next longest axis can be used.
Pass the point that corresponding to the median of the projection of all triangle centroids onto this axis.
OBBTree can be balanced.
Partition the polygons into two sub-groups based on their centroids.
After split, an OBB is found for each sub-group.
Building an OBBTreeTop-down approach
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
Building an OBBTreeTop-down approach
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
For a given triangle soap, compute an orientation of the triangles vertices (via the first and second order statistics): = average of all vertices C = the covariance matrix
Based on C The normalized orthogonal eigenvectors of C are
used as a basis - axes of the OBB. External vertices along each axis yields sizes of the
OBB.
Building an OBBTreeDerive a good-fit OBB -1
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
OBB for a polygon soap can also be found by computing an orientation of the triangles of the convex hull
The OBB will be less dependent on the distribution of polygons. The convex hull of an object is computed.
Can be done by, e.g., Quickhull algorithm. In return, we have n triangles, and based on which a covariance matrix
is derived. Centroid of the convex hull Covariance matrix
Normalized eigenvectors of C as the OBB’s axes. Min-max extent on each axis.
Building an OBBTreeDerive a good-fit OBB -2
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
CS Dept., NCTU, J. H. Chuang
Building an OBBTreeDerive a good-fit OBB -3
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
1
0
1
0
1
0
1
0
1
triangleof centroid the: 3/)(
triangleof area theis where,
1,,0 triangle,:
where
)()9(12
1
][))((1
n
k
kkH
H
iiii
kn
k
kH
kkk
Hin
k
kj
ki
kj
ki
kj
ki
kj
ki
k
H
ijTHiH
n
j
i
maa
m
irqpm
kaaa
nkrqp
mmrrqqppmma
Cmmmmn
C
In OBBTree, each OBB is stored with a rigid-body transformation (a rotation R and a translation vector t ) matrix MA.
When testing CD of OBBs A and B, The overlap test should be done in the coordinate
system of one of OBBs, say A. So A is now a AABB. Transform B into A’s coordinate system with
Fast Overlap Test for OBBsHandling Rigid-Body Motions
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
BAAB MMT 1
A naïve algorithm requires 144 edge-face test (12 edges x 6 faces x 2 boxes)
Separating axis theorem For any two arbitrary, convex, disjoint polyhedra, A and B, there exists
a separating axis where the projections of A and B are also disjoint. Checking for disjoint OBBS involves searching for a separating axis. If A and B are disjoint, then they can be separated by a separating axis
that is orthogonal to either A face of A, or A face of B, or An edge from each polyhedron.
Fast Overlap Test for OBBsSeparating Axis Theorem
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
CS Dept., NCTU, J. H. Chuang
Fast Overlap Test for OBBsSeparating Axis Theorem
Axes p and q are orthogonal to faces of A.Axes s and t are orthogonal to faces of B.It is sufficient to find one axis that separates the projection inorder to know that the OBBs do not overlap.Here, q is the only axis that separates the projections.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
General separating-plane test: 15 tests Three axes of A, Three axes of B, then Nine axes from A and B (9 axes).
Sequentially test for each axis candidate Do axis projection and form the interval on the axis. Two objects are disjoint if their intervals don't overlap. If the intervals overlap, boxes may or may not be disjoint. Further tests
on other axes may be needed.
More efficient way? What are the axes and in which order?
Fast Overlap Test for OBBsSeparating Axis Theorem
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation CS Dept., NCTU, J. H. Chuang
CS Dept., NCTU, J. H. Chuang
Fast Overlap Test for OBBs A fast separation test -1
Assume that a potential separating axis is l. Radii of the OBBs A and B on the axis l
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
,,
,,
lbhr
lahr
i
wvui
BiB
i
wvui
AiA
BA rrlt
l
l
i.e., disjoint. be should
on intervals then theaxis,
separating a is ifonly and If
CS Dept., NCTU, J. H. Chuang
Fast Overlap Test for OBBsA fast separation test -2
Done in the coordinate system of A Formed by A’s center and axes
ac, axes au, av , aw
B is assumed to be relative to A By separating axis theorem
It is sufficient to find one axis that separates A and B to be sure that they are disjoint.
Fifteen axes have to be tested 3 from the faces of A (axes of A: au, av , aw) 3 from the faces of B (axes of B: bu, bv , bw) 3x3=9 from combinations of edges from A and B (cij= ai x bj, i,j=u,v,w)
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang
Fast Overlap Test for OBBs A fast separation test -3
Simplify the expression by working in thecoordinate system of A: Case 1
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
020100
,,,,
,,,,
,)0 0 1(Let
rhrhrh
bhbhbh
abhlbhr
h
aahlahr
tatlt
al
Bw
Bv
Bu
wx
Bw
vx
Bv
ux
Bu
ui
wvui
Bi
i
wvui
BiB
Au
ui
wvui
Ai
i
wvui
AiA
xu
Tu
020100
222120
121110
020100
becomes test theSo
where
rhrhrhht
rrr
rrr
rrr
bbbR
Bw
Bv
Bu
Aux
wvu
CS Dept., NCTU, J. H. Chuang
Fast Overlap Test for OBBs A fast separation test -4
Simplify the expression by working in thecoordinate system of A: Case 2
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Bu
Aw
Av
Auzyx
Bu
ui
wvui
Bi
i
wvui
BiB
Aw
Av
Au
uz
Aw
uy
Av
ux
Au
ui
wvui
Ai
i
wvui
AiA
zyxuzz
uyy
uxx
u
u
hrhrhrhrtrtrt
hbbhlbhr
rhrhrhbhbhbh
bahlahr
rtrtrtbtbtbtbtlt
bl
201000201000
,,,,
201000
,,,,
201000
becomes test theSo
,Let
CS Dept., NCTU, J. H. Chuang
Fast Overlap Test for OBBs A fast separation test -5
000211212111
0002
,,,,,,
1121
,,,,,,
2111
becomes test theSo
)( )(
)()(
) 0()(
,Let
rhrhrhrhrtrt
rhrhbhbhbahbah
bbahbabhlbhr
rhrhbhbhabhabh
aabhbaahlahr
rtrtbtbtbbtbatlt
bal
Bw
Bu
Aw
Avyz
Bw
Bu
ux
Bw
wx
Bu
uuBw
wuBu
viu
wvui
Bi
vui
wvui
Bi
i
wvui
BiB
Aw
Av
vy
Aw
vz
Av
vvAw
wvAu
iuv
wvui
Ai
vui
wvui
Ai
i
wvui
AiA
yzvzy
vyz
Tvy
vz
vu
vu
Case 3
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
000211212111
0002
,,,,,,
1121
,,,,,,
2111
becomes test theSo
)( )(
)()(
) 0()(
,Let
rhrhrhrhrtrt
rhrhbhbhbahbah
bbahbabhlbhr
rhrhbhbhabhabh
aabhbaahlahr
rtrtbtbtbbtbatlt
bal
Bw
Bu
Aw
Avyz
Bw
Bu
ux
Bw
wx
Bu
uuBw
wuBu
viu
wvui
Bi
vui
wvui
Bi
i
wvui
BiB
Aw
Av
vy
Aw
vz
Av
vvAw
wvAu
iuv
wvui
Ai
vui
wvui
Ai
i
wvui
AiA
yzvzy
vyz
Tvy
vz
vu
vu
CS Dept., NCTU, J. H. Chuang
Fast Overlap Test for OBBs A fast separation test -6
If any of these 15 tests is positive, the OBBs are disjoint.
Number of operations Maximum 180, or 240 if transformation of B into A’s
coordinate system in included. Order of axes
Has an impact on performance. First test three axes of A
They are orthogonal and thus reject the overlap faster, and the simplest tests.
Then three axes of B, followed by the axes formed by axes of A and B.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang
Fast Overlap Test for OBBs Another fast separation test -7
Simply skip the last 9 axis tests can speed up the overlapping test, Geometrically, this is amount to doing two
AABB-AABB tests. But sometimes report two disjoint OBBs as
overlapping. In these cases, the recursion in the OBBTree
will go deeper than necessary.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang
Two-level CD system
Globally searching pairs of objects that have potential collision. Spatial subdivision Sweep-and-Prune
Collision detection on a pair of objects Hierarchical CD based on OBBTree,
AABBTree,… Polygon-polygon overlap test
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
CS Dept., NCTU, J. H. Chuang
Two-level CD system
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation
Simulation
Collision response
Pruning Multi-Body pairs(Sweep/Prune)
Exact collisionDetection (OBB tree)
CS Dept., NCTU, J. H. Chuang
Time-critical collision detection
Time critical computing needs to consider all computations involved in each frame update.
Two major computations Rendering and Collision detection
Time-critical collision detection Progressive refinement on the discrete-time collision
detection using hierarchical representations, such as Sphere tree, box tree (axis-aligned or oriented).
Hard to estimate the allocated time.
Animation (U) Chap 7 Physically Based AnimationAnimation (U) Chap 7 Physically Based Animation