Upload
others
View
11
Download
3
Embed Size (px)
Citation preview
Rigid Bodies
Simulation Homework
โข Build a particle system based either on F=ma or procedural simulation
โ Examples: Smoke, Fire, Water, Wind, Leaves, Cloth, Magnets, Flocks, Fish, Insects, Crowds, etc.
โข Simulate a Rigid Body
โ Examples: Angry birds, Bodies tumbling, bouncing, moving around in a room and colliding, Explosions & Fracture, Drop the camera, Etcโฆ
Thursday Simulation &
Unity
Rigid Body as โParticle Chunksโ
Consider a rigid body It can be broken up into chunks (or elements), and each chunk can be treated as a single particle if it is small enough
A small chunk of a rigid body
Center of Mass
โข A body composed of ๐ particle โchunksโ with masses ๐๐ has total mass
๐ =
๐=1
๐
๐๐
โข If the particles have positions ิฆ๐ฅ๐ , the center of mass is
าง๐ฅ =ฯ๐=1๐ ๐๐ ิฆ๐ฅ๐๐
โข The center of mass for a rigid body has position าง๐ฅ and translational velocity าง๐ฃ similar to a single particle
โข When we refer to the position and velocity of a rigid body, we are referring to the position and translational velocity of its center of mass
โข The center of mass obeys the same ODEs for position and velocity as a particle does, but using the TOTAL mass and the NET force
Orientation
Orientationโข A rigid body can rotate or change its orientation
while its center of mass is stationary
โข Different ways to keep track of the rotation ๐ :โ 3x3 Matrix, 3 Euler angles, 1 Quaternion
โข Place a coordinate system at the center of mass in object space
โข The rotation ๐ rotates the rigid body (and the object space coordinate system) into its world space orientation
โข Recall: the columns of ๐ are the three object space axes in their world space orientations
Combining Position and Orientation
าง๐ฅ
t
๐
๐ฅ๐ค๐ฅ๐
โข The rigid body has an intrinsic coordinate system in its object space, with its center of mass at the origin
โข Itโs put into world space with a translation and a rotation
Combining Position and Orientation
โข The translation of the origin of the object space coordinate system is given by the position of the center of mass าง๐ฅ
โข The world space orientation of the object space coordinate system is given by ๐
โ Assume ๐ is a matrix, equivalently expressed as a unit quaternion
โข A point ๐ฅ๐ in object space has a world space location๐ฅ๐ค = าง๐ฅ + ๐ ๐ฅ๐
โ Notice that the center of mass (at the origin) maps to าง๐ฅ
โ Notice that (1,0,0), (0,1,0), (0,0,1) are all rotated by ๐ before being translated by าง๐ฅ
Angular Velocity
โข Both าง๐ฅ and ๐ are functions of timeโข The rate of change of the position of the center of mass าง๐ฅ
with respect to time is the translational velocity of the center of mass าง๐ฃ
โข (From our quaternion discussionโฆ) The orientation of the body is changing as it is rotated about some axis เท๐ emanating from the center of mass
โข The rate of change of the orientation ๐ is given by the world space angular velocity ๐โ its direction is the axis of rotation, เท๐โ Its magnitude is the speed of rotation
โข The pointwise velocity of any point x on the rigid body is given by
๐ฃ๐ = าง๐ฃ + ๐ ร ๐ฅ โ าง๐ฅ = าง๐ฃ + ๐ ร ๐where r is the moment arm and ร is the cross-product
Angular Velocity
Aside: Cross Product Matrix
โข Given vectors ๐ = [๐1, ๐2, ๐3] and ๐ = ๐1, ๐2, ๐3 , their cross product ๐ ร ๐ can be written as matrix multiplication ๐โ๐ by converting ๐ to a cross product matrix
โข ๐โ =
0 โ๐3 ๐2๐3 0 โ๐1โ๐2 ๐1 0
โข ๐โ๐ = โ๐โ
โข ๐โ๐ = โ๐โ๐
โข Using this new notation, the pointwise velocity of any point x on the object is then given by:
๐ฃ๐ = าง๐ฃ + ๐โ๐
Linear and Angular Velocity
าง๐ฅ
าง๐ฃ
๐
ODE for Orientation
โข The ODE for orientation (angular position) is given by
แถ๐ = ๐โ๐
โข That is, แถ๐ = ๐ ร ๐ where the cross product is applied independently to each of the three columns of ๐
โข Writing the 3x3 matrix ๐โ and using matrix multiplication ๐โ๐ automatically performs these 3 cross products
Inertia Tensor
Inertia Tensor
โข Linear momentum is defined as the product of the mass times the translational velocityโ Mass is something that resists change in velocity
โข Angular momentum ๐ฟ is defined as an โangular massโ times the angular velocity ๐
โข The โangular massโ is called the moment of inertia (or inertia tensor) ๐ผ of the rigid body
โข If you spin in your chair while extending your legs, and then suddenly pull your legs closer the chair spins fasterโ ๐ผ reduces when you pull your legs closer.โ Hence ๐ has to increase to keep angular momentum ๐ฟ = ๐ผ๐
constant
Inertia Tensorโข For a system of n particles, the angular momentum is
๐ฟ =
๐
(๐ฅ๐๐ค)โ๐๐๐ฃ๐ =
๐
าง๐ฅ + ๐๐โ๐๐๐ฃ๐ = าง๐ฅโ๐ าง๐ฃ +
๐
๐๐โ๐๐๐ฃ๐
โ where ๐๐ is the moment arm of the ๐๐กโparticle
โข ๐ฃ๐ can be written as าง๐ฃ + ๐โ๐๐ so
๐ฟ = าง๐ฅโ๐ าง๐ฃ +
๐
๐๐โ๐๐ าง๐ฃ +
๐
๐๐โ๐๐๐
โ๐๐
โข ฯ๐ ๐๐โ๐๐ าง๐ฃ = ( าง๐ฃโ)๐ ฯ๐๐๐๐๐ = 0 so
๐ฟ = าง๐ฅโ๐ าง๐ฃ +
๐
๐๐(๐๐โ)๐๐๐
โ๐ = าง๐ฅโ๐ าง๐ฃ + ๐ผ๐
โ where ๐ผ = ฯ๐๐๐(๐๐โ)๐๐๐
โ
Object Space Inertia Tensorโข We can pre-compute the object space inertia tensor as a 3x3
matrix ๐ผ๐
โข Then, the world space inertia tensor is given by the 3x3 matrix
๐ผ = ๐ ๐ผ๐๐ ๐
โข One can compute the SVD of the symmetric 3x3 matrix ๐ผ๐ to obtain ๐ผ๐ = ๐๐ท๐๐ where ๐ท is a 3x3 diagonal matrix of 3 singular values
โข Then rotating the object space rest state of the rigid body by ๐โ1 gives a new object space inertia tensor of
๐โ1๐ผ๐๐โ๐ = ๐โ1๐๐ท๐๐๐โ๐ = ๐ท
โข That is, properly orienting the rest pose of a rigid body in object space gives a diagonal object space inertia tensor ๐ผ๐
Forces and Torques
Forces and Torquesโข Newtonโs second law for angular quantities
โข A force ๐น changes both the linear momentum ๐ าง๐ฃ and the rotational (angular) momentum ๐ฟ
โข The change in linear momentum is independent of the point on the rigid body ๐ฅ where the force is applied
โข The change in angular momentum does depend on the point ๐ฅ where the force is applied
โข The torque is defined as๐ = ๐ฅ โ าง๐ฅ ร ๐น = ๐ ร ๐น
โข The net change in angular momentum is given by the sum of all the external torques
แถ๐ฟ = ๐
ODEs
Rigid Body: Equations of Motion
โข State vector for a rigid body
๐ =
าง๐ฅ๐ ๐ าง๐ฃ๐ฟ
โข Equations of motion
๐
๐๐ก๐ =
๐
๐๐ก
าง๐ฅ๐ ๐ าง๐ฃ๐ฟ
=
าง๐ฃ๐โ๐ ๐น๐
Rigid Body: Equations of Motion
โข State vector for a rigid body
๐ =
าง๐ฅ๐ าง๐ฃ๐ฟ
โข Equations of motion
๐
๐๐ก๐ =
๐
๐๐ก
าง๐ฅ๐ าง๐ฃ๐ฟ
=
าง๐ฃ๐โ๐ ๐น/๐๐
Equations of motion for a particle at the center of mass
Forward Euler Update
๐๐+1 = ๐๐ + ฮ๐ก
าง๐ฃ๐โ๐ ๐น/๐๐
๐
โข Newmark for better accuracy and stability, etcโฆ
โข Better results are obtained on the second equation by rotating the columns of ๐ directly using the vector ฮ๐ก๐
โข Need to periodically re-orthonormalize the columns of ๐ to keep it a rotation matrix
Rigid Body: Equations of Motion
โข State vector for a rigid body
๐ =
าง๐ฅ๐าง๐ฃ๐ฟ
โข Equations of motion
๐
๐๐ก๐ =
๐
๐๐ก
าง๐ฅ๐าง๐ฃ๐ฟ
=
าง๐ฃ1
2๐โ๐
๐น/๐๐
โข Once again, preferable to rotate q by ฮ๐ก๐โข Renormalize q using a square root
Question #1
LONG FORM:โข Summarize rigid body simulation.โข Identify 10 rigid bodies in a typical room.
SHORT FORM:โข Identify 10 rigid bodies in this room.
Geometry
Rigid Body Modelingโข Store an object space triangulated surface to
represent the surface of the rigid body
โข Store an object space implicit surface to represent the interior volume of the rigid body
โข Collision detection between two rigid bodies can then be carried out by checking the surface of one body against the interior volume of another
โข Implicit surfaces can be used to model the interior volume of kinematic and static objects as well
โข Implicit surface representations of interior volumes can also be used for collisions with particles and particle systems
โข Implicit surfaces represent a surface with a function ๐(๐ฅ) defined over the whole 3D space
โข The inside region ฮฉโ, the outside region is ฮฉ+, and the surface ๐ฮฉ are all defined by the function ๐(๐ฅ)
โข ๐ ๐ฅ < 0 inside
โข ๐ ๐ฅ > 0 outside
โข ๐ ๐ฅ = 0 surface
โข Easy to check if a point is inside an object
โข Efficient to make topology changes to an object
โข Efficient boolean operations: Union, Difference, Intersection
Recall: Implicit Surfaces
Analytic Implicit Surfaces
โข For simple functions, write down the function and analytically evaluate ๐(๐ฅ) to see if ๐ ๐ฅ < 0 and thus ๐ฅ is inside the object
โข 2D circle
โข 3D ellipsoid
Discrete Implicit Surfaces
โข Lay down a grid that spans the space you are trying to represent, e.g. a padded bounding box
โข Store values of the function at grid points
โข Then for arbitrary locations in space, interpolate from the nearby values on the grid to see if ๐ ๐ฅ <0โข use trilinear interpolation, like 3D textures
โข Signed Distance Functions are implicit surfaces where the magnitude of the function gives the distance to the closet point on the surface
Constructing Signed Distance Functionsโข Start with a triangulated surfaceโข Place a grid inside a slightly padded bounding box of the object
โ This grid will contain point samples for the signed distance functionโ The resolution of the grid is based on heuristics
โข Place a sphere at every grid point and find all intersecting triangles โ the radius of the sphere only needs to be a few grid cells wide, because
we only care about grid points near the triangulated surfaceโ If the sphere does not intersect any triangles, then the grid point is not
near the triangulated surfaceโ (An acceleration structure is useful, e.g. bounding box hierarchy)
โข For each nearby triangle, find the closest point on that triangle โ see this document for details
โข Take the minimum of all such distances as the magnitude of ๐โข Could initialize all grid points this way, but it is expensive for points
farther from the surface where one has to check many more (potentially all) triangles
Fast Marching Methodโข Similar to Dijkstra's algorithm
โข Walk outwards from the previously initialized points to fill the rest of the domain
Initialization
โข Mark all the previously computed points nearby the triangulated surface as Black
โข Mark the rest of the points White
Iteration
โข White points adjacent to Black points are re-labeled as Red
โข Estimate the distance value for all Red points using only their Black neighbors
โ by solving a quadratic equation for distance
โข The Red point with the smallest distance value is found and labeled Black
โ a heap data structure is ideal, and then the fast marching method runs in ๐ช ๐๐๐๐๐ where ๐ is the number of grid points
โข Labeling this point Black turns some White points into Red
โ and also changes the value of some of the previously computed Red points, since there is a new Black point to use in their distance computation
Sign of ๐
โข Perform a flood fill on the gridโ Start from a random grid pointโ Put it on a stack; mark it as 0โ Pop it off; put its connected non-
occluded neighbors on the stack; mark them as 0; repeat
โ When there are no more cells on the stack, find a random uncolored cell, mark it as 1, and repeat
โข The region (0 or 1) that touches the grid boundary is marked as outside
โข The other region is marked as inside
โข Could have more than two regions in some cases
Question #2
LONG FORM:โข Summarize rigid body geometric modeling.โข Answer short form question below
SHORT FORM:โข Give an example of a rigid body with an interesting
shape that could be used in a game. How would it be used?
Collisions
Collision Detectionโข Test all the triangulated surface points of one body against the
implicit surface volume of the other (and vice versa)
โ A world space point is put into object space to check against an implicit surface using
๐ฅ๐ = ๐ โ1(๐ฅ๐ค โ าง๐ฅ)
โข Partial derivatives are used to compute the normal
๐ ๐ฅ0, ๐ฆ0, ๐ง0 = เธญ๐๐
๐๐ฅ,๐๐
๐๐ฆ,๐๐
๐๐ง๐ฅ0,๐ฆ0,๐ง0
๐๐๐๐๐๐ ๐ฅ0, ๐ฆ0, ๐ง0 =๐ ๐ฅ0, ๐ฆ0, ๐ง0๐ ๐ฅ0, ๐ฆ0, ๐ง0
โข Note: A particle can be moved to the surface of the implicit surface by tracing a ray in the normal direction and looking for the intersection with the ๐ = 0 isocontour (see CS148)
Rigid Body Collisions
Collision detection
๐ข1
๐ข2
Compute the initial relative velocity
The final relative velocity is calculated using the coefficient of restitution.
Calculate and apply the collision impulse
๐2
๐1
After evolving the bodies in time, they eventually separate
Collision Response
Equations for applying an impulse to one body with collision location ๐๐ with respect to its center of mass:
โข ๐ าง๐ฃ๐๐๐ค = ๐ าง๐ฃ + ๐
โข ๐ผ๐๐๐๐ค = ๐ผ๐ + ๐๐โ๐ (note ๐ผ doesnโt change)
โข And then, in terms of the pointwise velocityโฆ
โข ๐ข๐๐๐๐ค = าง๐ฃ๐๐๐ค + ๐๐๐๐คโ
๐๐ = าง๐ฃ๐๐๐ค + ๐๐โ๐๐๐๐๐ค
โข ๐ข๐๐๐๐ค = าง๐ฃ +
๐
๐+ ๐๐
โ๐ ๐ + ๐ผโ1๐๐โ๐
โข ๐ข๐๐๐๐ค = ๐ข๐ +
1
๐๐ผ3๐ฅ3 + ๐๐
โ๐๐ผโ1๐๐โ ๐ = ๐ข๐ + ๐พ๐
โข Infinite mass kinematic/static objects (e.g. ground plane) are treated by setting the impulse factor ๐พ = 0
Collision Responseโข Equal and opposite impulse applied to each body:
๐ข1๐๐๐ค = ๐ข1 + ๐พ1๐ and ๐ข2
๐๐๐ค = ๐ข2 โ ๐พ2๐
โข Calculate the relative velocity ๐ข๐๐๐ = ๐ข1 โ ๐ข2 at the point of collisionโ Relative normal velocity is ๐ข๐๐๐,๐ = ๐ข๐๐๐ โ ๐
โ Only collide when ๐ข๐๐๐,๐ < 0, i.e. bodies not already separating
โข Define a total impulse factor ๐พ๐ = ๐พ1 + ๐พ2, then
๐ข๐๐๐๐๐๐ค = ๐ข๐๐๐ + ๐พ๐๐
๐ข๐๐๐,๐๐๐๐ค = ๐ข๐๐๐,๐ +๐๐๐พ๐๐
โข Since the collision impulse should be in the normal direction, we can write ๐ = ๐๐๐, hence
๐ข๐๐๐,๐๐๐๐ค = ๐ข๐๐๐,๐ + ๐๐๐พ๐๐๐๐
โข Given ๐ข๐๐๐,๐๐๐๐ค = โ๐๐ ๐ข๐๐๐,๐, we solve for ๐๐ and apply ๐ = ๐๐๐
Frictionโข Relative tangential velocity is ๐ข๐๐๐,๐ = ๐ข๐๐๐ โ ๐ข๐๐๐,๐๐
โข First assume static friction, i.e. ๐ข๐๐๐,๐๐๐๐ค = 0, so that
๐ข๐๐๐๐๐๐ค = โ๐๐ ๐ข๐๐๐,๐๐
โข Solve for a full 3D impulse ๐ using ๐ข๐๐๐๐๐๐ค = ๐ข๐๐๐ + ๐พ๐๐, by inverting
the 3x3 matrix ๐พ๐โข If this impulse is in the friction cone, i.e. if ๐ โ ๐ โ ๐ ๐ โค ๐๐ ๐ โ ๐ ,
then the assumption of sticking due to static friction was correct
โข Otherwise we start over using kinetic friction instead (๐๐โค ๐๐ )
โ With tangential direction ๐ =๐ข๐๐๐,๐
๐ข๐๐๐,๐, the kinetic friction impulse
is ๐ = ๐๐๐ โ ๐๐๐๐๐
โ And we can solve โ๐๐ ๐ข๐๐๐,๐= ๐ข๐๐๐,๐ +๐๐๐พ๐ ๐ โ ๐๐๐ ๐๐ to find ๐๐ before applying ๐ = ๐ โ ๐๐๐ ๐๐
Question #3
LONG FORM:โข Summarize rigid body collision handling.โข Answer short form question below.
SHORT FORM:โข Give an example of using collisions between rigid
bodies for a game.
Fracture
Fracture
Fractureโข Suppose a rigid body fractures into n pieces with
masses ๐1, , ๐2 โฆ๐๐, velocities ๐ฃ1, ๐ฃ2โฆ . ๐ฃ๐, inertia tensors ๐ผ1, ๐ผ2, โฆ ๐ผ๐ and angular velocities ๐1, ๐2, โฆ๐๐
โข The mass and inertia tensor of each new piece can be computed based on the geometry
โข What can we say about the fractured pieces?โ M๐ฃ = ฯ๐๐๐ฃ๐โ ๐ผ๐ = ฯ(๐๐
โ๐๐๐ฃ๐ + ๐ผ๐๐๐)
โข To ensure this:โ Assign each rigid body the velocity its newly created center
of mass had before fracturing i.e. ๐ฃ๐ = ๐ฃ + ๐ ร ๐๐โข where ๐๐ points from the center of mass of the original rigid body to
the center of mass of the i-th child
โ Angular momentum is then conserved by setting ๐๐ = ๐