54
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics 1 Phun with Physics The basic ideas Vector calculus Mass, acceleration, position, …

Phun with Physics

Embed Size (px)

DESCRIPTION

Phun with Physics. The basic ideas Vector calculus Mass, acceleration, position, …. Some defs…. Kinematics The status of an object Position, orientation, acceleration, speed Describes the motion of objects without considering factors that cause or affect the motion Dynamics - PowerPoint PPT Presentation

Citation preview

Page 1: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics1

Phun with Physics

• The basic ideas• Vector calculus• Mass, acceleration, position, …

Page 2: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics2

Some defs…

• Kinematics – The status of an object

• Position, orientation, acceleration, speed• Describes the motion of objects without considering factors that

cause or affect the motion

• Dynamics– The effects of forces on the motion of objects.

Page 3: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics3

The basics• Let p(t) be the position in time. – We’ll drop the (t) and just say p

• Other values:– v – velocity– a - acceleration

2

2

dt

pd

dt

dva

dt

dpv

Velocity is the derivative of position

Acceleration is the derivative of velocity

Page 4: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics4

Vector calculus

• Really, p(t) is a triple, right?– Think of these equations as three equations, one for

each dimension– This is vector calculus

dt

dpdt

dpdt

dp

tv

tv

tv

z

y

x

z

y

x

)(

)(

)(

Page 5: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics5

Newton’s law and Momentum

• We know this one…

• Momentum

maF

mvM

Note: Force is the derivative of momentum

Page 6: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics6

What about real objects?

• Think of a real object as a bunch of points, each with a momentum– We can find a “center of mass” for the object and treat the

object as a point with the total mass

• We have:– Mass, position vector, acceleration vector, velocity vector

Page 7: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics7

Example: Air Resistance

• The resistance of air is proportional to the velocity– F = -kv

• We know F = ma, so: ma = -kv

kvdt

dvm

kvma

So, how can we solve?

Page 8: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics8

Euler’s method

tm

kvvv

tm

kvv

m

kv

dt

dv

kvdt

dvm

ii

1

Page 9: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics9

What about orientation?• We’ll start in 2D…• Let be the orientation (angle)– Easy in 2D, not so easy in 3D we’ll be back

• is the angular velocity around center of gravity• is the angular acceleration• Then…

dt

ddt

d

Page 10: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics10

What’s the velocity at a point?

cpp rvr

p

Chasles’ Theorem: Velocity at any point is the sum of linear and rotational components.

Radians are important, here

cpop rvv

Perpendicular to cpSame length!Perpendicularized radius vector

Page 11: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics11

Angular momentum

• Angular momentum– At a point?– For the whole thing?– M=mv

• Momentum equals mass times velocity• What does this mean?

Page 12: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics12

We want to know how much of the momentum is “around” the center

pcpcp MrL

rcp

cpr

pMAngular Momentumof a point around c

Page 13: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics13

Torque – Angular force

pcpcp MrL

pcpcp Fr

Torque at a point

Page 14: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics14

Total angular momentum and moment of inertia

I

dprm

dprmr

dprmr

dpvmr

dpMr

dpLL

cpp

cppcp

cppcp

ppcp

pcp

cpcT

2)(

cpp rvr

I is the moment of inertia for the object.

pcpcp MrL

Page 15: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics15

Moment of inertia

dprmI cpp 2)(

What are the characteristics?

What does large vs. small mean?

How to we get this value?

Page 16: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics16

Relation of torque and moment of inertia

Ia

Ia

Page 17: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics17

Simple dynamics

• Calculate/define center of mass (CM) and moment of inertia (I)

• Set initial position, orientation, linear, and angular velocities

• Determine all forces on the body• Linear acceleration is sum of forces divided by mass• Angular acceleration is sum of torques divided by I• Numerically integrate to update position, orientation,

and velocities

Page 18: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics18

Object collisions

• Imagine objects A and B colliding

B

A

Assume collision is point on plane

n

Page 19: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics19

What happens?

• ???

B

A

n

Page 20: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics20

Our pal Newton…

• Newton’s law of restitution for instantaneous collisions with no friction– is a coefficient of restitution

• 0 is total plastic condition, all energy absorbed• 1 is total elastic condition, all energy reflected

nvnv '

What’s the consequence of “no friction”?

Page 21: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics21

Impulse felt by each object

• Newton’s third law: equal and opposite forces– Force on A is jn (n is normal, j is amount of force)– Force on B is –jn– So…

nm

jvv

nm

jvv

BBB

AAA

'

'

No rotation for now…

B

A

n

We’ll need to know j

Page 22: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics22

Solving for j…

BA

BA

BAB

BA

A

BABA

mmnn

nvvj

nvvnnm

jnvnn

m

jnv

nvvnvv

11

))(1(

)(

)()''(

nm

jvv

nm

jvv

BBB

AAA

'

'Then plug j into…

Page 23: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics23

What about rotation?

A

AAA

AAA

I

jnr

nm

jvv

'

'

B

B

A

A

BA

BA

Inr

Inr

mmnn

nvvj

22 )()(11

))(1(

Page 24: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics24

How to determine the time of collision?• What do I mean?

• Ideas?

• Avoid “tunneling”: objects that move through each other in a time step

Page 25: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics25

Euler’s method

tm

kvvv

tm

kvv

m

kv

dt

dv

kvdt

dvm

ii

1

)),(()()(

...)(')),((

)()),((

ttvfttvttv

buttvttvfm

tkvttvf

We can write…

Page 26: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics26

The problem with Euler’s method

...!

...)(''!2

)(')()( 0

2

000

n

nn

t

x

n

ttx

tttxtxttx

Taylor series:

We’re throwing this away!

Error is O(t2)

)()(')()( 2000 tOttxtxttx

Half step size cuts error to ¼!

Page 27: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics27

Improving accuracy

• Supposed we know the second derivative?

)()(''!2

)(')()( 30

2

000 tOtxt

ttxtxttx

But, we would like to achieve this error without computing the second derivative.

We can do this using the Midpoint Method

)(,)),((2

)()()( 3000000 tOtttxf

ttxfttxttx

)()(')()( 2000 tOttxtxttx

Page 28: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics28

Midpoint Method

• 1. Compute an Euler step

• 2. Evaluate f at the midpoint

• 3. Take a step using the midpoint value.

),( txftx

2

,2midpoint

tt

xxfx

midpoint)()( xttxttx

Page 29: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics29

Example

m

tkvttvf

)()),((

),( txftx

2

,2midpoint

ttxxfx

midpoint)()( xttxttx Step 1

Step 2

Step 3

Page 30: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics30

Moving to 3D

• Some things remain the same– Position, velocity, acceleration

• Just make them 3D instead of 2D

• The killer: Orientation– “It’s possible to prove that no three-scaler

parameterization of 3D orientation exists that doesn’t ‘suck’, forsome suitably mathematically rigorous definition of ‘suck’.” Chris Hecker

Page 31: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics31

Orientation options

• Quaternions– We’ll use later

• Matricies– We’ll use this here.

Page 32: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics32

Variables

• x(t)– Spatial position in time (3D)– Center of mass at time t– Assume object has center of mass at (0,0,0)

• v(t)– Velocity in space

• q(t) – Orientation in time (quaternion)

Page 33: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics33

Angular velocity

• (t)– Angular velocity at any point in time– This is a rotation rate times a rotation vector

n

Strange, huh?

Page 34: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics34

Note

• Angular velocity is instantaneous– We’ll compute it later in equations, but we won’t keep it

around.– Angular velocity is not necessarily constant for a spinning

object!• Interesting! Can you visualize why?

Page 35: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics35

Angular velocity and vectors

• Rate of change of a vector is:

• This is why they like that notation– Change is orthogonal to the normal and vector– Magnitude of change is vector length times magnitude of

)()()( trttr

Page 36: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics36

Derivative of the rotation quaternion• Woa…

)(,0[)( tqttq

Normalize this sucker and we can take a Newton step.

Be sure to scale (t) by t.

Page 37: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics37

Velocity of a point (think vertex)

• Not just v(t), must include rotation!!!

)())()](,0([)()](,0[)( 10 tvtqtptqttp i

)()()()( 10 txtqptqtp ii Position of point at time t:

Just a reminder:

Velocity of point at time t:

And the magic:

Angular part Linear part

)(,0[)( tqttq

)()](,0))[()()]((,0[

)()](,0))[()()()()]((,0[

)()](,0[)()()](,0[

)())()](,0([)()](,0[)(

1

110

110

10

tvttxtpt

tvttxtxtqptqt

tvttqptqt

tvtqtptqttp

i

i

i

Page 38: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics38

Force and torque

• Fi(t)– Force on particle i at time t– Vector, of course

)())()(()( tFtxtpt iii

)()( tFtF i

)()()()()( tFtxtptt iii

Torque on point i:

Total Force:

Total Torque:

Page 39: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics39

Linear Momentum

)()( tMvtP Momentum:

M

tPtv

)()(

)()( tFtP And, the derivative of momentum is force:

M

tFtv

)()(

Page 40: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics40

Angular Momentum

• Angular momentum is preserved if no torque is applied.

• L(t) is the angular momentum

)()( ttL

Page 41: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics41

Inertia Tensor

)''(''''

'')''(''

'''')''(

)(22

22

22

iyixiiyiziixizi

iziyiizixiixiyi

izixiiyixiiziyi

rrmrrmrrm

rrmrrmrrm

rrmrrmrrm

tI

All that work typing this sucker in and it’s pretty much useless. Orientation dependent!

Page 42: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics42

Inertia Tensor for a base orientation

Tiii

Tiibody ppIppmI 0000

dxdydzyxzyxyzdxdydzzyxxzdxdydzzyx

yzdxdydzzyxdxdydzzxzyxxydxdydzzyx

xzdxdydzzyxxydxdydzzyxdxdydzzyzyx

Ibody

))(,,(),,(),,(

),,())(,,(),,(

),,(),,())(,,(

22

22

22

22

22

22

00

00

00

hw

dw

dh

Ibox

Page 43: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics43

Base inertia tensor to current inertia tensor

Tbody tRItRtI )()()(

)()()( ttItL

Relation of angular momentum and inertia tensor:

Page 44: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics44

Bringing it all together

• Current state:

)(

)(

)(

)(

)(

tL

tP

tq

tx

tY

Position

Orientation

Linear momentum

Angular momentum

)(

)(

)(,0[

)(

)(

)(

)(

)(

)(

t

tF

tqt

tv

tL

tP

tq

tx

dt

dtY

)()()( 1 tLtIt

Velocity (may itself be updated)

)()( tFtF i

)()()()()( tFtxtptt iii

Page 45: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics45

3D Collisions

• There are now two possible types of collisions– Not just vertex to face

Page 46: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics46

3D collisions

• Vertex to face

• Edge to edge

Page 47: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics47

We need…

• 3D collision detection– We’ll do that later

• Determine when the collision occurred– Binary search for the time– Bisection technique

Page 48: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics48

Velocity at a point

))()(()()()( txtpttvtp aaaaa

)()()( 1 tLtIt

Position (center of gravity)

Position of point

Velocity (linear)

Angular velocity

Page 49: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics49

Relative velocity

))()(()( tptptnv barel

Normal to object b

Vertex to face: normal for face

Edge to edge: cross product of edge directions

Positive vrel means moving apart, ignore it

Negative vrel means interpenetrating, process it

What does zero vrel mean?

Page 50: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics50

New velocities for a and b

aaa M

tjntvtv

)()()(

))()()(()()( 1 tjntrtItt aaaa

bbb M

tjntvtv

)()()(

))()()()((()()( 1 tjntxtptItt bbbbb

)()()( txtptr aaa

)()()( txtptr bbb Let: Vector from center

of mass to point

Velocity (linear) update

Mass

Normal

Angular velocity update

Inertia tensor inverse

Equivalent equations for b

Page 51: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics51

And j…

bbbaaaMM

rel

rtnrItnrtnrItn

vj

ba

)(()())(()(

)1(1111

Page 52: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics52

Contrast 2D/3D

aaa M

tjntvtv

)()()(

aaa M

tjntvtv

)()()(

a

aaa I

tjnrtt

)()()(

))()()(()()( 1 tjntrtItt aaaa

2D 3D

Page 53: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics53

Questions?

• 2D had two different j’s– Linear velocity and angular velocity

• 3D gets by with only one.– Why is this?

Page 54: Phun with Physics

CSE 872 Dr. Charles B. OwenAdvanced Computer Graphics54

Other issues

• Resting contact– Bodies in contact, but – < vrel <

– Must deal with motion transfer