Rigid body dynamics
Rigid body simulation
Once we consider an object with spatial extent, particle system simulation is no longer sufficient Rigid body simulation
• Unconstrained system • no contact • Constrained system • collision and contact Problems
Performance is important! Problems
Control is difficult! Particle simulation
x(t) Y(t)= Position in phase space ! v(t) "
v(t) Y˙ (t)= Velocity in phase space ! f(t)/m " Rigid body concepts
Translation Rotation
Position Orientation Linear velocity Angular velocity Mass Inertia tensor Linear momentum Angular momentum Force Torque • Position and orientation
• Linear and angular velocity
• Mass and Inertia
• Force and torques
• Simulation Position and orientation
Translation of the body x x(t)= y z
Rotation of the body
rxx ryx rzx R(t)= rxy ryy rzy rxz ryz rzz x(t) and R ( t ) are called spatial variables of a rigid body Body space
Body space
A fixed and unchanged space where the shape of a rigid body y0 is defined
r0i The geometric center of the x0 rigid body lies at the origin of the body space z0 Position and orientation
Body space World space
y0
r0i y0 R(t)
r0i z0 x0
y x t x0 ( ) z 0 z x Position and orientation
World space Use x(t) and R(t) to transform the body space into world space y0
R(t) r0i What’s the world coordinate of an arbitrary point r0i on the body? z0 x0
y x(t) ri(t)=x(t)+R(t)r0i
z x Position and orientation
• Assume the rigid body has uniform density, what is the physical meaning of x(t)? • center of mass over time • What is the physical meaning of R(t)? • it’s a bit tricky Position and orientation
Consider the x-axis in body space, (1, 0, 0), what is the direction of this vector in world space at time t?
1 rxx R(t) 0 = rxy 0 rxz
which is the first column of R(t)
R(t) represents the directions of x, y, and z axes of the body space in world space at time t Position and orientation
• So x(t) and R(t) define the position and the orientation of the body at time t • Next we need to define how the position and orientation change over time • Position and orientation
• Linear and angular velocity
• Mass and Inertia
• Force and torques
• Simulation Linear velocity
Since x ( t ) is the position of the center of mass in world space, x˙ ( t ) is the velocity of the center of mass in world space
v(t)=x˙ (t) Angular velocity
• If we freeze the position of the COM in space • then any movement is due to the body spinning about some axis that passes through the COM • Otherwise, the COM would itself be moving Angular velocity
We describe that spin as a vector ω(t)
Direction of ω ( t ) ? Magnitude of | ω ( t ) | ?
d v t x t Linear position and velocity are related by ( )=dt ( )
How are angular position (orientation) and velocity related? Angular velocity
How are R ( t ) and ω ( t ) related? Hint: Consider a vector c ( t ) at time t specified in world space, how do we represent c˙ ( t ) in terms of ω(t)
ω(t) |c˙(t)| = |b||ω(t)| = |ω(t) × b|
b c˙ c˙(t)=ω(t) × b = ω(t) × b + ω(t) × a a c c˙(t)=ω(t) × c(t) Angular velocity
Given the physical meaning of R ( t ) , what does each column of R ˙ ( t ) mean? At time t, the direction of x-axis of the rigid body in world space is the first column of R(t)
rxx rxy rxz At time t, what is the derivative of the first column R t of ( ) ? ˙ rxx rxx r = !(t) r 2 xy 3 ⇥ 2 xy 3 rxz rxz 4 5 4 5 Angular velocity
rxx ryx rzx R˙ (t)= ω(t) × rxy ω(t) × ryy ω(t) × rzy rxz ryz rzz
This is the relation between angular velocity and the orientation, but it is too cumbersome
We can use a trick to simplify this expression Angular velocity
Consider two 3 by 1 vectors: a and b, the cross product of them is aybz − byaz a × b = −axbz + bxaz axby − bxay
Given a, let’s define a* to be a skew symmetric matrix
0 −az ay az 0 −ax −ay ax 0
0 −az ay bx ∗ then a b = az 0 −ax by = a × b −ay ax 0 bz Angular velocity
rxxrxx ryxryx rzx rzx ∗ ∗ ∗ R˙ (t)= ω(t) × rxyrxy ωω(t()t) × ryyryy ω(tω)(t) ×rzy rzy rxzrxz ryzryz rzz rzz
∗ = ω(t) R(t)
Vector relation: c˙(t)=ω(t) × c(t)
∗ Matrix relation: R˙ = ω(t) R(t) Perspective of particles
• Imagine a rigid body is composed of a large number of small particles • the particles are indexed from 1 to N
• each particle has a constant location r0i in body space • the location of i-th particle in world space at time t is ri(t)=x(t)+R(t)r0i Velocity of a particle
d r t r t ω∗R t r v t ˙( )=dt ( )= ( ) 0i + ( ) ∗ = ω (R(t)r0i + x(t) − x(t)) + v(t)
∗ = ω (ri(t) − x(t)) + v(t)
r˙ i(t)=ω × (ri(t) − x(t)) + v(t)
angular component linear component Velocity of a particle
r˙ i(t)=ω × (ri(t) − x(t)) + v(t)
y0 ω(t) ω(t) × (ri(t) − x(t))
ri (t) v t x(t) ( ) r˙ i(t) y x z0 v(t) 0 z x • Position and orientation
• Linear and angular velocity
• Mass and Inertia
• Force and torques
• Simulation Mass
The mass of the i-th particle is mi
N Mass M = ! mi i=1
! miri(t) Center of mass in world space M
What about center of mass in body space? (0, 0, 0) Center of mass
Proof that the center of mass at time t in word space is x(t)
! miri(t) M =
= x(t) Inertia tensor
Inertia tensor describes how the mass of a rigid body is distributed relative to the center of mass
02 02 mi(riy + riz) mirix0 riy0 mirix0 riz0 02 02 I = 2 miriy0 rix0 mi(rix + riz) miriy0 riz0 3 02 02 i mir0 r0 mir0 r0 mi(r + r ) X 6 iz ix iz iy ix iy 7 4 5 ! ri = ri(t) − x(t)
I(t) depends on the orientation of a body, but not the translation
For an actual implementation, we replace the finite sum with the integrals over a body’s volume in world space Inertia tensor
• Inertia tensors vary in world space over time • But are constant in the body space • Pre-compute the integral part in the body space to save time Inertia tensor
Pre-compute Ibody that does not vary over time
2 100 mirix0 mirix0 riy0 mirix0 riz0 T 2 I(t)= m r0 r0 010 mir0 r0 mir0 mir0 r0 i i i 2 3 2 iy ix iy iy iz 3 001 m r r m r r m r 2 X i iz0 ix0 i iz0 iy0 i iz0 4 5 4 5 I r!T r! 1 − r! r!T (t)=! mi( i i) i i )
T T = ! mi((R(t)r0i) (R(t)r0i)1 − (R(t)r0i)(R(t)r0i) )
T T − T T = ! mi(R(t)(r0ir0i)R(t) 1 R(t)r0ir0iR(t) )
T T T = R(t) mi((r r0i)1 − r0ir ) R(t) !" 0i 0i #
I t R t I R t T I m rT r 1 − r rT ( )= ( ) body ( ) body = ! i(( 0i 0i) 0i 0i) i Inertia tensor
Pre-compute Ibody that does not vary over time
2 100 mirix0 mirix0 riy0 mirix0 riz0 T 2 I(t)= m r0 r0 010 mir0 r0 mir0 mir0 r0 i i i 2 3 2 iy ix iy iy iz 3 001 m r r m r r m r 2 X i iz0 ix0 i iz0 iy0 i iz0 4 5 4 5 I r!T r! 1 − r! r!T (t)=! mi( i i) i i )
T T = ! mi((R(t)r0i) (R(t)r0i)1 − (R(t)r0i)(R(t)r0i) )
T T − T T = ! mi(R(t)(r0ir0i)R(t) 1 R(t)r0ir0iR(t) )
T T T = R(t) mi((r r0i)1 − r0ir ) R(t) !" 0i 0i #
I t R t I R t T I m rT r 1 − r rT ( )= ( ) body ( ) body = ! i(( 0i 0i) 0i 0i) i Approximate inertia tensor
• Bounding boxes
• Pros: simple
• Cons: inaccurate Approximate inertia tensor
• Point sampling
• Pros: simple, fairly accurate
• Cons: expensive, requires volume test Approximate inertia tensor
• Green’s theorem
F · ds = (∇×F) · da !∂D !!D • Pros: simple, exact
• Cons: require boundary representation • Position and orientation
• Linear and angular velocity
• Mass and Inertia
• Force and torques
• Simulation Force and torque
Fi(t) denotes the total force from external forces acting on the i-th particle at time t y 0 τ(t)=(ri(t) − x(t)) × Fi(t)
F(t)=! Fi(t) ri (t) i x(t) Fi(t)
τ(t)= (ri(t) − x(t)) × Fi(t) ! z0 x0 i
y
z x Force and torque
•F(t) conveys no information about where the various forces acted on the body •τ(t) contains the information about the distribution of the forces over the body •Which one depends on the location of the particle relative to the center of mass? Linear momentum
P(t)=! mir˙i(t) i
= ! miv(t)+ω(t) × ! mi(ri(t) − x(t)) i i = Mv(t)
Total linear moment of the rigid body is the same as if the body was simply a particle with mass M and velocity v(t) Angular momentum
Similar to linear momentum, angular momentum is defined as
L(t)=I(t)ω(t)
Does L(t) depend on the translational effect x(t)? Does L(t) depend on the rotational effect R(t)? What about P(t)? Derivative of momentum
Change in linear momentum is equivalent to the total forces acting on the rigid body
P˙ (t)=Mv˙ (t)=F(t)
The relation between angular momentum and the total torque is analogous to the linear case
L˙ (t)=τ(t) Derivative of momentum
L˙ r! × F Proof (t)=τ(t)=! i i
!∗ !∗ mir¨i − Fi = mi(v˙ − r˙ i ω − ri ω˙ ) − Fi = 0
!∗ − !∗ − !∗ − !∗ ! ri mi(v˙ r˙ i ω ri ω˙ ) ! ri Fi = 0
!∗ !∗ !∗ !∗ − mir r˙ ω − mir r ω˙ = τ !" i i # !" i i #
− r!∗r!∗ r!T r! 1 − r! r!T I ! mi i i = ! mi(( i i) i i )= (t)
!∗ !∗ − mir r˙ ω + I(t)˙ω = τ !" i i # d I˙ t −m r!∗r!∗ −m r!∗r!∗ − m r!∗r!∗ ( )=dt ! i i i = ! i i ˙ i i ˙ i i d I˙ t ω I t ω I t ω L˙ t τ ( ) + ( )˙ = dt( ( ) )= ( )= • Position and orientation
• Linear and angular velocity
• Mass and Inertia
• Force and torques
• Simulation Equation of motion
x(t) position v(t) ∗ R(t) orientation d ω(t) R(t) Y(t)= Y(t)= P(t) linear momentum dt F(t) L(t) angular momentum τ(t)
Constants: M and Ibody P t v t ( ) ( )= M
T I(t)=R(t)IbodyR(t)
−1 ω(t)=I(t) L(t) Momentum vs. velocity
• Why do we use momentum in the phase space instead of velocity? • Because the relation of angular momentum and torque is simple • Because the angular momentum is constant when there is no torques acting on the object • Use linear momentum P(t) to be consistent with angular velocity and acceleration Example:
1. compute the Ibody in body space
y x0 y0 z0 2 2 , , − y0 + z0 00 ! 2 2 2 " M 2 2 Ibody = 0 x0 + z0 0 12 2 2 00x0 + y0
x
−x0 −y0 z0 ! 2 , 2 , 2 " z Example:
1. compute the Ibody in body space
y 2. rotation free movement
(−3, 0, 2) (3, 0, 2) x
F z F Example:
1. compute the Ibody in body space
y 2. rotation free movement
3. translation free movement
(−3, 0, 2) (3, 0, 2) x
F z F Force vs. torque puzzle
10 sec later
Suppose a force F acts on the block at the center F F of mass for 10 seconds. Since there is no torque acting on the block, the body will only acquire linear velocity v after 10 seconds. The kinetic 1 energy will be MvT v 2 1 MvT v energy = 0 energy = 2
Now, consider the same force acting off-center to the body for 10 seconds. Since it is the same force, the velocity of the center of mass after 10 seconds is the same v. However, the block will also pick up 1 1 some angular velocity ω. The kinetic energy will be MvT v + ωT Iω 2 2 F If identical forces push the block in both cases, how can the energy of energy = 0 the block be different? Notes on implementation
• Using quaternion instead of transformation matrix • more compact representation • less numerical drift Quaternion
w x 1 0 q(t)= q˙ (t)= q(t) 2 y 3 2 !(t) 6 z 7 6 7 4 5
quaternion multiplication Equation of motion
v(t) x(t) position 1 0 q(t) orientation d 2 q(t) 3 Y(t)= Y(t)= 2 !(t) 2 3 linear momentum dt P(t) 6 F(t) 7 angular momentum 6 7 6 L(t) 7 6 ⌧(t) 7 6 7 6 7 4 5 4 5
Constants: M and Ibody P t v t ( ) ( )= M
T I(t)=R(t)IbodyR(t)
−1 ω(t)=I(t) L(t) Exercise
Consider a 3D sphere with radius 1m, mass 1kg, and inertia Ibody. The initial linear and angular velocity are both zero. The initial position and the initial orientation are x0 and R0. The forces applied on the sphere include gravity (g) and an initial push F applied at point p. Note that F is only applied for one time step at t0. If we use Explicit Euler method with time step h to integrate , what are the position and the orientation of the sphere at t2? Use the actual numbers defined as below to compute your solution (except for g and h). What’s next? • Collision, collision, collision
• Read: Unconstrained rigid body dynamics by Baraff and Witkin