Rigid Body Dynamics CSE169: Computer Animation Instructor: Steve Rotenberg UCSD, Winter 2005 Cross Product i j k a b ax ay az bx by bz a b a y bz a z by a z bx a x bz a x by a y bx Cross Product a b a y bz a z by a z bx a x bz c ab c x 0 bx a z by a y bz c y a z bx 0 by a x bz c z a z bx a x by 0 bz a x by a y bx Cross Product c x 0 bx a z by a y bz c y a z bx 0 by a x bz c z a z bx a x by 0 bz cx 0 c a y z c z a y az 0 ax a y bx a x by 0 bz Cross Product cx 0 c a y z c z a y a b aˆ b 0 aˆ a z a y az 0 ax az 0 ax a y bx a x by 0 bz ay ax 0 Derivative of a Rotating Vector Let’s say that vector r is rotating around the origin, maintaining a fixed distance At any instant, it has an angular velocity of ω dr ωr dt r ω r ω Derivative of Rotating Matrix If matrix A is a rigid 3x3 matrix rotating with angular velocity ω This implies that the a, b, and c axes must be rotating around ω The derivatives of each axis are ωxa, ωxb, and ωxc, and so the derivative of the entire matrix is: dA ω A dt ˆ A ω Product Rule The product rule defines the derivative of products d ab da db ba dt dt dt d abc da db dc bc a c ab dt dt dt dt Product Rule It can be extended to vector and matrix products as well d a b da db b a dt dt dt d a b da db b a dt dt dt d A B dA dB B A dt dt dt Dynamics of Particles Kinematics of a Particle x dx v dt 2 dv d x a 2 dt dt position veloc ity accelerati on Mass, Momentum, and Force m mass p mv momentum dp f ma dt force Moment of Momentum The moment of momentum is a vector L rp Also known as angular momentum (the two terms mean basically the same thing, but are used in slightly different situations) Angular momentum has parallel properties with linear momentum In particular, like the linear momentum, angular momentum is conserved in a mechanical system Moment of Momentum L is the same for all three of these particles p • p • r3 L rp r2 p r1 • Moment of Momentum L is different for all of these particles p • p • L rp r2 p r3 • r1 Moment of Force (Torque) The moment of force (or torque) about a point is the rate of change of the moment of momentum about that point dL τ dt Moment of Force (Torque) L rp dL dr dp τ p r dt dt dt τ vp rf τ v mv r f τ rf Rotational Inertia L=rxp is a general expression for the moment of momentum of a particle In a case where we have a particle rotating around the origin while keeping a fixed distance, we can re-express the moment of momentum in terms of it’s angular velocity ω Rotational Inertia L rp L r mv mr v L mr ω r mr r ω L mrˆ rˆ ω L I ω I mrˆ rˆ Rotational Inertia I mrˆ rˆ 0 I m rz ry rz 0 rx r r I m rx ry rx rz 2 y 2 z ry 0 rx rz 0 ry rx ry ry rz 0 rx 2 z ry rx 0 ry rz 2 2 rx ry rx rz r r 2 x rz Rotational Inertia m r r I mrx ry mrx rz 2 y L I ω 2 z mrx ry m r r 2 x 2 z mry rz mrx rz mry rz 2 2 m rx ry Rotational Inertia The rotational inertia matrix I is a 3x3 matrix that is essentially the rotational equivalent of mass It relates the angular momentum of a system to its angular velocity by the equation L I ω This is similar to how mass relates linear momentum to linear velocity, but rotation adds additional complexity p mv Systems of Particles n mtotal mi tota l mass of all particles i 1 x cm mx m i i position of center of mass i p cm p i mi v i to tal momentum Velocity of Center of Mass v cm v cm v cm dx cm d dt dt m x m dx i mi dt mi p cm mtotal p cm mtotalv cm i i i m v m i i i Force on a Particle The change in momentum of the center of mass is equal to the sum of all of the forces on the individual particles This means that the resulting change in the total momentum is independent of the location of the applied force p cm p i dp cm d p i dp i f i dt dt dt Systems of Particles The total moment of momentum around the center of mass is: L cm ri p i L cm x i x cm p i Torque in a System of Particles L cm ri p i τ cm τ cm τ cm dL cm d ri p i dt dt d ri p i dt ri f i Systems of Particles We can see that a system of particles behaves a lot like a particle itself It has a mass, position (center of mass), momentum, velocity, acceleration, and it responds to forces fcm fi We can also define it’s angular momentum and relate a change in system angular momentum to a force applied to an individual particle τ cm ri fi Internal Forces If forces are generated within the particle system (say from gravity, or springs connecting particles) they must obey Newton’s Third Law (every action has an equal and opposite reaction) This means that internal forces will balance out and have no net effect on the total momentum of the system As those opposite forces act along the same line of action, the torques on the center of mass cancel out as well Kinematics of Rigid Bodies Kinematics of a Rigid Body For the center of mass of the rigid body: x cm dx cm v cm dt 2 dv cm d x cm a cm 2 dt dt Kinematics of a Rigid Body For the orientation of the rigid body: A 3x3 orientatio n matrix ω angular ve locity dω ω dt angular accelerati on Offset Position Let’s say we have a point on a rigid body If r is the world space offset of the point relative to the center of mass of the rigid body, then the position x of the point in world space is: x x cm r Offset Velocity The velocity of the offset point is just the derivative of its position x x cm r dx dx cm dr v dt dt dt v v cm ω r Offset Acceleration The offset acceleration is the derivative of the offset velocity v v cm ω r dv dv cm dω dr a r ω dt dt dt dt a a cm ω r ω ω r Kinematics of an Offset Point The kinematic equations for an fixed point on a rigid body are: x x cm r v v cm ω r a a cm ω r ω ω r Dynamics of Rigid Bodies Rigid Bodies We treat a rigid body as a system of particles, where the distance between any two particles is fixed We will assume that internal forces are generated to hold the relative positions fixed. These internal forces are all balanced out with Newton’s third law, so that they all cancel out and have no effect on the total momentum or angular momentum The rigid body can actually have an infinite number of particles, spread out over a finite volume Instead of mass being concentrated at discrete points, we will consider the density as being variable over the volume Rigid Body Mass With a system of particles, we defined the total mass as: n m mi i 1 For a rigid body, we will define it as the integral of the density ρ over some volumetric domain Ω m d Rigid Body Center of Mass The center of mass is: x cm xd d Rigid Body Rotational Inertia ry2 rz2 d I rx ry d rx rz d I xx I I xy I xz I xy I yy I yz I xz I yz I zz rx rz d 2 2 r r x z d ry rz d 2 2 ry rz d r r x y d rx ry d Diagonalization of Rotational Inertial I xx I I xy I xz I xy I yy I yz I A I0 A T I xz I yz I zz where I x I0 0 0 0 Iy 0 0 0 I z Derivative of Rotational Inertial dI dt dI dt dI dt dI dt dI dt d A I0 A dt T dA I dt dA 0 A A I0 dt T ω A I 0 AT A I 0 ω A T ˆ A ω I A I 0 ω T ˆ T ωI I ω ˆT ω I A I 0 AT ω ˆ ω I I ω T Derivative of Angular Momentum L I ω dL dI dω τ ω I dt dt dt ˆ ω I ω τ ω I I ω ˆ ω I ω τ ωI ω I ω τ ωI ω I ω Newton-Euler Equations f ma τ ωI ω I ω Applied Forces & Torques f cg f i τ cg ri f i 1 a f m 1 ω I τ ω I ω Properties of Rigid Bodies m I x v A ω a ω p mv L I ω f ma τ r f ω I ω I ω Rigid Body Simulation RigidBody { void Update(float time); void ApplyForce(Vector3 &f,Vector3 &pos); private: // constants float Mass; Vector3 RotInertia; // Ix, Iy, & Iz from diagonal inertia // variables Matrix34 Mtx; // contains position & orientation Vector3 Momentum,AngMomentum; // accumulators Vector3 Force,Torque; }; Rigid Body Simulation RigidBody::ApplyForce(Vector3 &f,Vector3 &pos) { Force += f; Torque += (pos-Mtx.d) x f } Rigid Body Simulation RigidBody::Update(float time) { // Update position Momentum += Force * time; Mtx.d += (Momentum/Mass) * time; // Mtx.d = position // Update orientation AngMomentum += Torque * time; Matrix33 I = Mtx·I0·MtxT // A·I0·AT Vector3 ω = I-1·L float angle = |ω| * time; // magnitude of ω Vector3 axis = ω; axis.Normalize(); Mtx.RotateUnitAxis(axis,angle); }