Physics in Computer Graphics A Brief Introduction
Franklin Fang 5/23/2013
What is the connection of the above two images?
• • Both famous because of an “Apple”. Many People like IOS because it is physically correct in Graphics • The icons rendered in optically correct way [skeuomorphism] • The scrolling works like spring, mechanically correct • Apps such as Angry Birds and Cut the Rope
Physics in Graphics
Ray-Tracing; Depth of Field; Motion Blur, etc
Rendering: Optics
Rigid Body; Elastic Body; Fluid, etc
Modeling: Mechanics
Not Wave Optics! Not Quantum Mechanics! Both Classical (17th ~ 18th Century optics and mechanics)
Application of Mechanics in Graphics (Entertainment)
Movie Game
Simulation of Rigid Body Dynamics Some have springs. (Easier, So Real Time!)
Simulation of Fluid, Smoke, Elastic Body, Hair, Cloth, Explosion,Building Fracture, etc. (Lots of Computation, not real time)
Application of Mechanics in Graphics (Research)
Bio-mechanics for Artificial Life(Real Time)
Artificial Fish by XiaoYuan Tu, Demetri
Virtual Surgery(Real Time)
My Own Artificial Millipede
UCLA Professor: Joseph Teran
http://www.youtube.com/watch?v=RxnRHIqefdU
http://youtu.be/LVbdBszrlxM
Particle Systems
• WebGL Demos :
http://www.liquidthought.com/sandbox/sandbox.html http://jarrodoverson.com/static/demos/particleSystem/ http://html5-pro.com/wormz/
Particle Systems(No force)
• Position x = (x,y,z) • Velocity v = dx/dt • Given an array of particles X = {x1,x2,x3..} and a static/changing velocity filed v(x,t), at each time step, for each particle, update position by dt*v(x)
xi (t + dt ) = xi (t ) + ∆t ⋅ v( xi (t ), t )
Particle Systems(force field) (The trajectory for angry birds)
xi vi
mi
Mass of particle i Position of particle I Velocity of particle i
2
dvi d xi f i (t ) = mi ai (t ) = mi = mi 2 dt dt
Numerical Schemes
Forward (Explicit) Euler Method: Use current time step force and velocity
Backward(Implicit) Euler Method: Use future time step force and velocity
No big difference when force is independent of position.
Start Each Frame
In your Code
• Initiate the position, velocity and force for each particle object.
• Calculate the force, for eg. constant gravity; • Use the force to update the velocity; • Use the velocity to update the position; • Draw the ball on its position.
Collision Detection Against Plane
Collision Resolution
Collision Resolution
Rigid Body (The collapse in angry bird)
• Three Translational degrees of freedom: • Three Rotational degrees of freedom:
θ
x
http://www.youtube.com/watch?v=J9HaT23b-xc
Start
In your code
• Initiate the Center of mass, Moment of Inertia, Rotation, Velocity, Angular Velocity and Force on each rigid body.
Each Frame
• Calculate Force and Torque (Need to solve for collision detection and collision handling) • Update the Velocity and Angular Velocity • Update the Position and Rotation • Draw the object in position and rotation
Spring-Damper System
Demo Cloth, Hair 1D String
• • • https://www.youtube.com/watch?v=45QxOhFpDSk Game Hair http://www.youtube.com/watch?v=ib1vmRDs8Vw Game Cloth http://www.youtube.com/watch?v=2FTpltiN4ig VFX Cloth
Spring-Damper System (The Slingshot in Angrybird)
A simple way to model deformable objects
A spring-damper connecting two particles
Spring-Damper System
Other Forces
• Friction Force (stabilize the system)
– Friction Force is typically proportional to the speed of the node – Friction Factor
• External Force for manipulation
– Need to solve the pick problem – Directly add to the total force on the picked node
In your Code
• First Init all the properties of nodes and spring-dampers • Within Each Frame(Forward Euler Method)
– Calculate and sum up all the forces – Update the Velocity of nodes – Update the Position of nodes – Draw everything
Numerical Schemes
Forward (Explicit) Euler Method: Use current time step force and velocity
xi (t + dt ) = xi (t ) + vi (t ) * dt
Backward(Implicit) Euler Method: Use future time step force and velocity
Big difference when force is dependent of position of many other particles.
• Achieved by solving systems of partial differential equations • Continuum mechanics define the equations. • Apply advanced numerical methods to solve the equations (Finite Element Method) • Eg: Teran’s virtual surgery.