Broad-Phase Collision Detection. Introduction It is computationally very expensive to test two...

41
Broad-Phase Collision Detection

Transcript of Broad-Phase Collision Detection. Introduction It is computationally very expensive to test two...

Broad-Phase Collision Detection Broad-Phase Collision Detection

Broad-Phase Collision Detection

IntroductionIntroduction It is computationally very expensive to test two arbitrary It is computationally very expensive to test two arbitrary

objects for collision.objects for collision. A naïve approach would be to clip every face from an A naïve approach would be to clip every face from an

object against the faces on the other object.object against the faces on the other object. Such an algorithm would have a quadratic running time, Such an algorithm would have a quadratic running time,

O(O(mm2), where ), where mm is the number of faces. is the number of faces. Even simple problems scenes have a handful of objects.Even simple problems scenes have a handful of objects. If If nn is the number of objects ( is the number of objects (nn-body problem) considering -body problem) considering

every possible pairwise test of the every possible pairwise test of the nn objects would require objects would require O(O(nn22))

The goal of The goal of broad-phase collision detectionbroad-phase collision detection is to is to quickly prune expensive and unnecessary pairwise tests. quickly prune expensive and unnecessary pairwise tests.

Broad-Phase Collision Detection

The four Principles for Dynamic The four Principles for Dynamic AlgorithmsAlgorithms

The Approximation PrincipleThe Approximation Principle The Locality PrincipleThe Locality Principle The Coherence PrincipleThe Coherence Principle The Kinematic PrincipleThe Kinematic Principle

Broad-Phase Collision Detection

The Approximation PrincipleThe Approximation Principle Complex geometry of an object can be Complex geometry of an object can be

approximated with a simple geometryapproximated with a simple geometry• Frequently used approximation geometries are:Frequently used approximation geometries are:• Axes Aligned Bounding Boxes (AABB)Axes Aligned Bounding Boxes (AABB)• SpheresSpheres• Oriented Bounding Boxes (OBB)Oriented Bounding Boxes (OBB)• CylindersCylinders

Broad-Phase Collision Detection

The Locality PrincipleThe Locality Principle This principle essentially states This principle essentially states

that objects lying sufficiently far that objects lying sufficiently far away from each other do not need away from each other do not need to be considered as overlapping.to be considered as overlapping.

One needs to come up with a way One needs to come up with a way to determine when things are to determine when things are sufficiently far away. sufficiently far away.

If we draw arrows (see, Figure) If we draw arrows (see, Figure) between the center of mass of between the center of mass of objects, which are close objects, which are close neighbors, the potential set of neighbors, the potential set of pairwise tests drop to only 42.pairwise tests drop to only 42.

Broad-Phase Collision Detection The Coherence PrincipleThe Coherence Principle By coherence we mean a measure of By coherence we mean a measure of

how much things change.how much things change. Object positions and orientations Object positions and orientations

change a little bit from frame to change a little bit from frame to frame in Figure.frame in Figure.

High coherence indicates that we High coherence indicates that we would have to compute almost the would have to compute almost the exactsame result in the next iteration.exactsame result in the next iteration.

Four kinds of coherence are usally Four kinds of coherence are usally considered:considered:- - Spatial Spatial - Geometric- Geometric- Frame- Frame- Temporal- Temporal

Broad-Phase Collision Detection The Kinematics PrincipleThe Kinematics Principle When we can benefit from knowing When we can benefit from knowing

something about the objects trajectory in the something about the objects trajectory in the near future, we say that we exploit the near future, we say that we exploit the Kinematics Principle.Kinematics Principle.

Broad-Phase Collision Detection Sweep and PruneSweep and Prune Time complexity of a brute-force search (a testing Time complexity of a brute-force search (a testing

the AABB of every possible object pair) is O(the AABB of every possible object pair) is O(nn2)) Sweep and Prune (coordinate) sorting allows Sweep and Prune (coordinate) sorting allows

obtaining a far better time complexity.obtaining a far better time complexity. In the 1D case, the AABBs simply are bounded In the 1D case, the AABBs simply are bounded

(sorted) intervals on the coordinate axis.(sorted) intervals on the coordinate axis.

Broad-Phase Collision Detection Sweep and PruneSweep and Prune The idea is to let a sweep line go The idea is to let a sweep line go

from minus infinity to infinity from minus infinity to infinity along the coordinate axis, and along the coordinate axis, and update a status set, update a status set, SS, with , with every endpoint encountered:every endpoint encountered:

• If the sweep-line hits a starting If the sweep-line hits a starting endpoint, i.e., endpoint, i.e., bbii, then object , then object ii is is added to the added to the SS..

• If the sweep-line hits an ending If the sweep-line hits an ending endpoint, i.e., endpoint, i.e., eeii, then object , then object ii is is removed from the removed from the SS..

• The extension to higher The extension to higher dimension is straightforward. dimension is straightforward.

Broad-Phase Collision Detection Sweep and PruneSweep and Prune Sweep and Prune requires that a list is sorted in increasing Sweep and Prune requires that a list is sorted in increasing

order.order. There are several sorting algorithms: quick sort, bubblesort, There are several sorting algorithms: quick sort, bubblesort,

insertion sort, etc.insertion sort, etc. The most popular is insertion sort. The worst-case time The most popular is insertion sort. The worst-case time

complexity of insertion sort is O(complexity of insertion sort is O(nn22).).

Fortunately in the context of physics-based animation, we can Fortunately in the context of physics-based animation, we can expect a high coherence, which means that the intervals of the expect a high coherence, which means that the intervals of the AABBs along the coordinate axis only chnge slightly from AABBs along the coordinate axis only chnge slightly from invocation to invocation.invocation to invocation.

Broad-Phase Collision Detection Sweep and PruneSweep and Prune Nevertheless, there are still situations where Sweep and Nevertheless, there are still situations where Sweep and

Prune has a quadratic running time as shown in FigurePrune has a quadratic running time as shown in Figure

Five rigid balls are falling under gravity along the Five rigid balls are falling under gravity along the yy-axis -axis and colliding with a fixed object.and colliding with a fixed object.

In this case, insertion sort is passed a list of interval In this case, insertion sort is passed a list of interval endpoints along the endpoints along the yy-axis, which is sorted in reverse -axis, which is sorted in reverse order.order.

Broad-Phase Collision Detection Sweep and PruneSweep and Prune So far we have assumed that no two endpoints have So far we have assumed that no two endpoints have

the same coordinate value along a given coordinate the same coordinate value along a given coordinate axis.axis.

If this happens, the algorithm will not report an If this happens, the algorithm will not report an overlap. In practice this can have fatal overlap. In practice this can have fatal consequences.consequences.

A missing overlap means that no contact are A missing overlap means that no contact are detected further down the collision detection detected further down the collision detection pipeline, thus the simulator might fail to react on a pipeline, thus the simulator might fail to react on a touching contact.touching contact.

Broad-Phase Collision Detection Multilevel griddingMultilevel gridding Another approach to broad-phase Another approach to broad-phase

collision detection is to use a spatial collision detection is to use a spatial data structure, such a rectilinear grid.data structure, such a rectilinear grid.

A multilevel gridding algorithm based on A multilevel gridding algorithm based on double chained list was introduced by V. double chained list was introduced by V. Savchenko in Savchenko in [ Simulation of dynamic [ Simulation of dynamic interaction between rigid bodies with time-interaction between rigid bodies with time-dependent implicitly defined surfaces, Parallel dependent implicitly defined surfaces, Parallel Computing and Transputers, Proceedings of the Computing and Transputers, Proceedings of the 6th Australian Transputer and Occam User 6th Australian Transputer and Occam User Group Conference, Brisbane, Australia, ed. D. Group Conference, Brisbane, Australia, ed. D. Arnold et al., IOS Press, November 1993, 122-Arnold et al., IOS Press, November 1993, 122-129]129]

The simulated world is divided into The simulated world is divided into rectilinear grid as shown in Figurerectilinear grid as shown in Figure

Broad-Phase Collision Detection

Multilevel griddingMultilevel gridding Space is partitioned into volume element (VE), Space is partitioned into volume element (VE),

which are usually axis aligned cuboids. For every which are usually axis aligned cuboids. For every VE list of the objects having common points with VE list of the objects having common points with thisVE is created. thisVE is created.

Broad-Phase Collision Detection

Multilevel griddingMultilevel gridding Every cell is identified by a triplet (Every cell is identified by a triplet (ii,,jj,,kk) in ) in

3D3D Allcells in the tiling that overlap with a Allcells in the tiling that overlap with a

given AABB are easily found by identifying given AABB are easily found by identifying the triplets spanned by the mapping of the the triplets spanned by the mapping of the minimum, minimum, ppmin, and maximum point,, and maximum point, p pmax, of , of the given AABB. the given AABB.

Chained list is used to store an additional Chained list is used to store an additional information such as size and orientation of information such as size and orientation of aligned bounding boxes, velocities of the aligned bounding boxes, velocities of the objects, color and so on as it illustrated in objects, color and so on as it illustrated in the Figure fromthe Figure from [[E. Ohbuchi and V. Savchenko, E. Ohbuchi and V. Savchenko, Java Distributed Processing of Implicitly Defined Java Distributed Processing of Implicitly Defined Geometric Objects, Proceedings of The Eights Geometric Objects, Proceedings of The Eights International Conference on Distributed Multimedia International Conference on Distributed Multimedia Systems, Sept. 26-28, San Francisco, California, Systems, Sept. 26-28, San Francisco, California, 2002, 52-59 2002, 52-59 ..

Broad-Phase Collision Detection

Using the Kinematic PrincipleUsing the Kinematic Principle If we have a function describing If we have a function describing

how the center of mass moves we how the center of mass moves we can approximate the trajectory in can approximate the trajectory in the near future, or predict extreme the near future, or predict extreme points as shown in Figure.points as shown in Figure.

For small steps the trajectory For small steps the trajectory computed will be a close computed will be a close approximation to the true approximation to the true trajectory of the object.trajectory of the object.

Intersection ray/sphere or Intersection ray/sphere or ray/polygon can be used to ray/polygon can be used to eliminate a lot of unnecessary eliminate a lot of unnecessary calculations.calculations.

Intersections: ray/sphereIntersections: ray/sphere The intersection between a ray (starting at the point The intersection between a ray (starting at the point P(xP(x00, y, y00, z, z00) )

and direction vector and direction vector vv (v (vxx, v, vyy, v, vzz) ) and a sphere (with the center and a sphere (with the center at point at point C(l, m, n) C(l, m, n) and the radius and the radius rr is easy to compute. Let us is easy to compute. Let us substitute coordinates substitute coordinates xx, , yy, and , and zz of a point in the surface of the of a point in the surface of the sphere sphere

(x - l)(x - l)2 2 + (y - m)+ (y - m)2 2 + (z - n)+ (z - n)2 2 = r= r2 2

by the parametric representation of a point on the rayby the parametric representation of a point on the ray x = xx = x0 0 + v+ vxx t, y = y t, y = y0 0 + v+ vyy t, z = z t, z = z0 0 + v+ vz z t.t.

As the result we obtain a quadratic equation in As the result we obtain a quadratic equation in t t of the form of the form atat2 2 + bt + c = 0+ bt + c = 0

If the determinant of this equation If the determinant of this equation D < 0 D < 0 then the line does not then the line does not intersect the sphere. If intersect the sphere. If D = 0 D = 0 the line is tangent to the sphere. the line is tangent to the sphere. The real roots give front and back intersection. Substituting The real roots give front and back intersection. Substituting roots in the parametric line equation yields coordinates of roots in the parametric line equation yields coordinates of intersection points.intersection points.

Intersections: ray/polygonIntersections: ray/polygon Intersection with a polygon is performed in Intersection with a polygon is performed in

three steps:three steps: Calculate the value of the parameter Calculate the value of the parameter tt (refer to (refer to

parametric equation of line in the previous slide) at parametric equation of line in the previous slide) at the intersection point with the plane the intersection point with the plane Ax+By+Cz+D Ax+By+Cz+D =0 =0 containing the polygon:containing the polygon:

Calculate the coordinates of the intersection point Calculate the coordinates of the intersection point Check whether this point is located inside the Check whether this point is located inside the

polygon. polygon. • The latter two steps can be avoided if The latter two steps can be avoided if tt parameter parameter

value is bigger than the distance to the already value is bigger than the distance to the already found intersection point with another object. found intersection point with another object.

zyx CrBrAr

DCzByAxt

000

Deformable SurfacesDeformable Surfaces

Hooke's Law for Damped Hooke's Law for Damped SpringSpring

where where aa and and bb are two are two particle connected with a particle connected with a spring, spring, kks is a spring is a spring constant, constant, ll = = rra – – r r b is the is the vector connecting the two vector connecting the two particles, particles, II = = vva – – v v b is the is the vector of instantaneous vector of instantaneous change, and change, and R R is the length is the length of the spring at rest.of the spring at rest.

Deformable SurfacesDeformable Surfaces

Classically, Classically, clothcloth was modeled by using mass- was modeled by using mass-spring systems.spring systems.

These are essentially particle systems with a These are essentially particle systems with a set of predefined springs between pairs of set of predefined springs between pairs of particles. particles.

The cloth is modeled as a regular 2D grid The cloth is modeled as a regular 2D grid where the grid nodes correspond to particles.where the grid nodes correspond to particles.

Three types of springs are used, see Figure.Three types of springs are used, see Figure.

Deformable SurfacesDeformable Surfaces

One deficiency with modeling cloth this way is One deficiency with modeling cloth this way is that it is limited to rectangular pieces of cloth.that it is limited to rectangular pieces of cloth.

A generalization is based on the observation A generalization is based on the observation that structural springs correspond to a 1-that structural springs correspond to a 1-neighborhood stencil in the rectilinear grid; neighborhood stencil in the rectilinear grid; sgearing and bending springs correspond to a sgearing and bending springs correspond to a 2-neighborhood stencil. See Figure.2-neighborhood stencil. See Figure.

Deformable SurfacesDeformable Surfaces In [Baraff, D. and Witkin A. (1998). Large In [Baraff, D. and Witkin A. (1998). Large

steps in cloth simulation, In Proceedings of steps in cloth simulation, In Proceedings of the 25the 25thth annual conference on CG and annual conference on CG and Intearctive Techniques, pp.43-45], an implicit Intearctive Techniques, pp.43-45], an implicit method for simulating cloth with a particle method for simulating cloth with a particle system is presented.system is presented.

Particles are defined on a grid and connected Particles are defined on a grid and connected in a in a triangular meshtriangular mesh. .

Deformable SurfacesDeformable Surfaces Defining the general position for the total system Defining the general position for the total system rr as as

we write Newton’s second law of motion aswe write Newton’s second law of motion as

where where ff is the corresponding general forc vector, and is the corresponding general forc vector, and MM is a digonal matrix with [ is a digonal matrix with [mm11, , mm22, …, , …, mmnn] along the ] along the diagonal.diagonal.

For cloth, typical internal forces considered are For cloth, typical internal forces considered are bending, stretching, and shearing, while external bending, stretching, and shearing, while external forces are typically gravity and forces are typically gravity and collision constraintscollision constraints. .

An implicit integration scheme is applied. An implicit integration scheme is applied.

Deformable SurfacesDeformable Surfaces

To define the stretching, To define the stretching, bending, and shearing bending, and shearing forces, a piece of cloth that forces, a piece of cloth that has topology as a plane, has topology as a plane, implying that cloth can be implying that cloth can be spread out in a single layer, spread out in a single layer, is consedered.is consedered.

A coordinate system A coordinate system intrinsic to the cloth, (intrinsic to the cloth, (uu((i,ji,j), ), vv((i,ji,j), where (), where (i,ji,j) are the ) are the indices of a particle is usedindices of a particle is used

We can then calculate the We can then calculate the mapping between the mapping between the intrinsic and the world intrinsic and the world coordinates as depicted in coordinates as depicted in FigureFigure

xx((i,ji,j) = w() = w(uu((i,ji,j), ), vv((i,ji,j)) ))

Deformable SurfacesDeformable Surfaces

As an example of using hierarchical As an example of using hierarchical structures consider an approach used in the structures consider an approach used in the paper [paper [M. Sugihara and V. Savchenko, M. Sugihara and V. Savchenko, A A Combination of Hierarchical Structures and Combination of Hierarchical Structures and Particle Systems for Self-Collision Detection Particle Systems for Self-Collision Detection of Deforming Objects, 2007of Deforming Objects, 2007

Algorithms for collision detection between rigid Algorithms for collision detection between rigid objects don’t work well for self-collision detection.objects don’t work well for self-collision detection.

An algorithm devoted to self-collision detection is An algorithm devoted to self-collision detection is necessary.necessary.

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision

Our approachOur approach Particle systems Particle systems [Senin, Kojekin, [Senin, Kojekin,

Savchenko 03]Savchenko 03] Hierarchical structuresHierarchical structures

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision

Construction of a boundingvolume hierarchy

Particle systemsdetect a collision possibility?

Hierarchical structuresdetect a collision possibility?

Polygon-polygon collision checks

YesYes

ApproachApproach

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision Particle systems Particle systems Particles work as Particles work as

sensors to detect sensors to detect collisions.collisions.

Particles move on Particles move on objects according to objects according to a physical law.a physical law.

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision

Particle systems for self-collision detectionParticle systems for self-collision detection We extend particle systems for self-collision detection.We extend particle systems for self-collision detection.

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision

Original distance and directionOriginal distance and direction Red LineRed Line::

Straight line (SL)Straight line (SL) Blue LineBlue Line::

Original distance line (ODL)Original distance line (ODL) The reason why original The reason why original

distance is necessary is that distance is necessary is that self-collision more often occurs self-collision more often occurs for contact points of the for contact points of the polygons yet close to a straight polygons yet close to a straight line (Red line) and far in the line (Red line) and far in the direction of the original direction of the original distance along of a deformable distance along of a deformable object (Blue line). object (Blue line).

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision InteractionInteraction Attractive forcesAttractive forces Repulsive forcesRepulsive forces The total force which affectsThe total force which affects i i-th -th

particle is as follows:particle is as follows: wherewhere fafa and and frfr denote functions for denote functions for

attraction and repulsion, attraction and repulsion, rsrs denotes the denotes the SL distance between particles and SL distance between particles and roro denotes the original distance between denotes the original distance between particles, particles, t t is a viable, and is a viable, and aa and and bb are are constants. We define constants. We define tt as a variable to as a variable to move particles yet close in a SL and far in move particles yet close in a SL and far in the ODL. the ODL.

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision Self-collision detection in Self-collision detection in particle systemsparticle systems

Update particle positionsThe distance between

closest particles is less thantolerance distance?

Hierarchical self-collision detection

Yes

The number of moving particles <= Nmin|| The number of particle update steps = Nmax

Yes

No

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision Hierarchical Hierarchical

structuresstructures Normal bounding volume Normal bounding volume

hierarchies are not hierarchies are not suitable for self-collision suitable for self-collision detection. detection.

We use “positive vector” We use “positive vector” [Volino et al 95][Volino et al 95] for self-collision for self-collision detection: a vector which has positive dot product with detection: a vector which has positive dot product with the normal vectors of all polygons of a deformable object the normal vectors of all polygons of a deformable object

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision

NodeNode Polygon (only LEAF node)Polygon (only LEAF node)

Left and Right (only NODE node)Left and Right (only NODE node)

Bounding volume (use AABBs)Bounding volume (use AABBs)

Positive vectorPositive vector

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision

Positive vectorPositive vector Positive vector is a vector which has positive dot Positive vector is a vector which has positive dot

product with the normal vectors of all polygons.product with the normal vectors of all polygons.

A positive vector exists in anode of a deformable object

Bounding volume based self-collisiondetection is called in the node

No

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision Flow chart of our systemFlow chart of our system

Construction of a boundingvolume hierarchy

Particle systemsdetect a collision possibility?

Hierarchical structuresdetect a collision possibility?

Polygon-polygon collision checks

YesYes

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision

ImplementationImplementation Modeling the cloth for experimentsModeling the cloth for experiments Mass spring systemsMass spring systems

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision Results Results

0500

10001500200025003000350040004500

0

200

400

600

800

1000

1200

1400

1600

1800

2000

2200

2400

Time step

Num

ber

of p

olyg

on-p

olyg

onco

llisi

on c

heck

particles no particles

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision Results Results

0

500

1000

1500

2000

2500

3000

0

1000

2000

3000

4000

5000

6000

7000

8000

9000

1000

0

Time step

Num

ber

of p

olyg

on-p

olyg

onco

llisi

on c

heck

particles no particles

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision Results Results Animation3.aviAnimation3.avi

02000400060008000

100001200014000160001800020000

0

200

400

600

800

1000

1200

1400

1600

1800

2000

2200

2400

Time step

Num

ber

of p

olyg

on-p

olyg

onco

llisi

on c

heck

particles no particles

A Combination of Hierarchical A Combination of Hierarchical Structures and Particle Systems Structures and Particle Systems for Self-Collisionfor Self-Collision Future workFuture work Improving the procedure of self-Improving the procedure of self-

collision detection after particles detect collision detection after particles detect a possibility a possibility

Investigating applicability for objects Investigating applicability for objects with changing topologywith changing topology