Transcript Document

Particle Systems Mohan Sridharan

Based on slides created by Edward Angel CS4395: Computer Graphics 1

Introduction

• Most important of procedural methods: • Used to model: – Natural phenomena: • Clouds.

• Terrain.

• Plants.

– Crowd Scenes.

– Real physical processes.

CS4395: Computer Graphics 2

Newtonian Particle

• • Particle system is a set of particles.

Each particle is an ideal point mass.

• Six degrees of freedom: – Position.

– Velocity.

• Each particle obeys Newton's law: f = ma CS4395: Computer Graphics 3

Particle Equations

• Define position and velocity: p i v i = (x i , y i = dp i z i ) /dt = p i ‘ = (dx i /dt, dy i /dt , z i /dt) m v i ‘ = f i • Hard part is defining force vector.

CS4395: Computer Graphics 4

Force Vector

• Independent Particles : – – – Gravity.

Wind forces.

O(n) calculation.

• Coupled Particles O(n): – – Meshes.

Spring-Mass Systems.

• Coupled Particles O(n 2 ): – Attractive and repulsive forces.

CS4395: Computer Graphics 5

Solution of Particle Systems

float time, delta state[6n], force[3n]; state = initial_state(); for(time = t0; time){ force = force_function(state, time); state = ode(force, state, time, delta); render(state, time) }

CS4395: Computer Graphics 6

Simple Forces

• Consider force on particle i:

f

i =

f

i (

p

i ,

v

i ) • Gravity

f

i =

g

.

g

i = (0, -g, 0) • Wind forces.

• Drag.

p

i (t 0 ),

v

i (t 0 ) CS4395: Computer Graphics 7

Meshes

• • Connect each particle to its closest neighbors.

– O(n) force calculation.

Use spring-mass system: CS4395: Computer Graphics 8

Spring Forces

• Assume each particle has unit mass and is connected to its neighbor(s) by a spring.

• Hooke’s law: force proportional to distance (d = ||

p q

||) between the points.

– CS4395: Computer Graphics 9

Hooke’s Law

• Let s be the distance when there is no force:

f

= -k s (|

d

| - s)

d

/|

d

| k s is the spring constant.

d

/|

d

| is a unit vector pointed from

p

to

q

.

• Each interior point in the mesh has four forces applied on it.

CS4395: Computer Graphics 10

Spring Damping

• • A pure spring-mass will oscillate forever!

Must add a damping term.

f

= -(k s (|

d

| - s) + k d

·

/|

d

|)

d

/|

d

| • Must project velocity: CS4395: Computer Graphics 11

Attraction and Repulsion

• Inverse square law:

f

= -k r

d

/|

d

| 3 • General case requires O(n 2 ) calculation.

• In most problems, not many particles contribute to the forces on any given particle.

• Sorting problem: is it O(n log n)?

CS4395: Computer Graphics 12

Boxes

• • • • Spatial subdivision technique.

Divide space into boxes.

Particle can only interact with particles in its box or the neighboring boxes.

Must update which box a particle belongs to after each time step.

CS4395: Computer Graphics 13

Linked Lists

• Each particle maintains a linked list of its neighbors.

• Update data structure at each time step.

• Must amortize cost of building the data structures initially.

CS4395: Computer Graphics 14

Particle Field Calculations

• Consider simple gravity.

• We do not compute forces due to sun, moon, and other large bodies  • Rather we use the gravitational field.

• Usually we can group particles into equivalent point masses.

CS4395: Computer Graphics 15

Solution of ODEs

• • • Particle system has 6n ordinary differential equations.

Write set as d

u/

dt = g(

u

,t) Solve by approximations : Taylor’s theorem.

CS4395: Computer Graphics 16

Euler’s Method

u

(t + h) ≈

u

(t) + h d

u

/dt =

u

(t) + h

g

(

u

, t) • Per step error is O(h 2 ).

• Require one force evaluation per time step • Problem is numerical instability: depends on step size.

CS4395: Computer Graphics 17

Improved Euler

u

(t + h) ≈

u

(t) + h/2(

g

(

u

, t) +

g

(

u

, t+h)) • Per step error is O(h 3 ).

• • Also allows for larger step sizes.

But requires two function evaluations per step.

• Also known as Runge-Kutta method of order 2 CS4395: Computer Graphics 18

Contraints

• • • • Easy in computer graphics to ignore physical reality.

Surfaces are virtual.

Must detect collisions separately if we want exact solution.

Can approximate with repulsive forces.

CS4395: Computer Graphics 19

Collisions

• Once we detect a collision, we can calculate new path.

• Use coefficient of restitution.

• Reflect vertical component.

• May have to use partial time step.

CS4395: Computer Graphics 20

Contact Forces

CS4395: Computer Graphics 21

Other Topics

• Language-based models: Section 11.7.

• Recursive methods and fractals: Section 11.8.

• Procedural noise: Section 11.9.

• Examples in Appendix (A.18).

CS4395: Computer Graphics 22