Computer graphics & visualization Collisions. computer graphics & visualization Simulation...

Preview:

Citation preview

computer graphics & visualization

Simulation and Animation

Collisions

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Collisions

• Avoidance

• Detection

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Detection• Broad

Phase

•Narrow Phase

•Detection

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Broad Phase

• Bounding Volume

(Hierarchies)

• Space Partitioning

Schemes

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Bounding Volumes• Key idea:

– Surround the object with a (simpler) bounding object (the bounding volume).

– If something does not collide with the bounding volume, it does not collide with the object inside.

– Often, to intersect two objects, first intersect theirbounding volumes

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Choosing a Bounding Volume• Lots of choices, each with tradeoffs• Tighter fitting is better

– More likely to eliminate “false” intersections

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Choosing a Bounding Volume• Lots of choices, each with tradeoffs• Tighter fitting is better• Simpler shape is better

– Makes it faster to compute with

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Choosing a Bounding Volume• Lots of choices, each with tradeoffs• Tighter fitting is better• Simpler shape is better• Rotation Invariant is better

– Easier to update as object moves

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Choosing a Bounding Volume• Lots of choices, each with tradeoffs• Tighter fitting is better• Simpler shape is better• Rotation Invariant is better• Convex is usually better

– Gives simpler shape, easier computation

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Bounding Volumes: Sphere• Rotationally invariant

– Usually• Usually fast to compute with• Store: center point and radius

– Center point: object’s centerof mass

– Radius: distance of farthest point on object from centerof mass.

• Often not very tight fit

• 10/59

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Axis Aligned Bounding Box (AABB)• Very fast to compute with• Store: max and min along x,y,z axes.

– Look at all points and record max, min• Moderately tight fit• Must update after rotation, unless

a loose box that encompasses thebounding sphere

• 11/59

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Common Bounding Volumes: k-dops• k-discrete oriented polytopes• Same idea as AABBs, but use more axes.• Store: max and min along fixed set of axes.

– Need to project points onto other axes.• Tighter fit than AABB, but also a bit more work.

• 12/59

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group • 13/59

Choosing axes for k-dops• Common axes: consider axes coming

out from center of a cube:• Through faces: 6-dop

– same as AABB• Faces and vertices: 14-dop• Faces and edge centers: 18-dop• Faces, vertices, and edge centers; 26-

dop• More than that not really helpful• Empirical results show 14 or 18-dop

performs best.

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Oriented Bounding Box (OBB)• Store rectangular parallelepiped oriented to best fit the object• Store:

– Center– Orthonormal set of axes– Extent along each axis

• Tight fit, but takes work to get good initial fit• OBB rotates with object, therefore only

rotation of axes is needed for update• Computation is slower than for AABBs,

but not as bad as it might seem

• 14/59

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Convex Hull• Very tight fit (tightest convex bounding volume)• Slow to compute with• Store: set of polygons forming convex hull • Can rotate CH along with object.• Can be efficient for some

applications

• 15/59

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Testing for Collision• Will depend on type of objects and bounding

volumes.• Specialized algorithms for each:

– Sphere/sphere– AABB/AABB– OBB/OBB– Ray/sphere– Triangle/Triangle

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group • 17/59

Collision Test Example: Sphere-Sphere• Find distance between centers of spheres• Compare to sum of sphere radii

– If distance is less, they collide• For efficiency, check squared distance vs.

square of sum of radii

d r2

r1

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Collision Test Example: AABB vs. AABB• Project AABBs onto axes

– i.e. look at extents• If overlapping on all axes, the boxes overlap.• Same idea

for k-dops.

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Collision Test Example: OBB vs. OBB• Similar to overlap test for k-dops• How do we find axes to test for overlap?

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Separating Axis Theorem• Two convex shapes do not overlap if and only if

there exists an axis such that the projections of the two shapes do not overlap

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Enumerating Separating Axes• 2D: check axis aligned with normal of each face• 3D: check axis aligned with normals of each

face and cross product of each pair of edges

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Enumerating Separating Axes• 2D: check axis aligned with normal of each face• 3D: check axis aligned with normals of each

face and cross product of each pair of edges

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Enumerating Separating Axes• 2D: check axis aligned with normal of each face• 3D: check axis aligned with normals of each

face and cross product of each pair of edges

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Bounding VolumesHierarchies

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group • 25/59

Intersecting Bounding Volume Hierarcies• For object-object collision detection• Keep a queue of potentially intersecting BVs

– Initialize with main BV for each object• Repeatedly pull next potential pair off queue and test

for intersection.– If that pair intersects, put pairs of children into

queue. – If no child for both BVs, test triangles inside

• Stop when we either run out of pairs (thus no intersection) or we find an intersecting pair of triangles

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

BVH Collision Test example

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

B-Volume Examples

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Space partitioningWhy space partitioning?

The best object is the one that isnot going to be processed!

– Processing means• Determining the spatial relationships between objects

– Do objects intersect – collision detection– Naive approach has complexity O(n2) (n polygons in the scene)

• Can also be: Rendering– Are objects within the visible space – visibility culling– Are objects occluded – occlusion culling

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Hierarchies of space partitions

– (Regular Grid)– Quadtree, Octree– BSP-Trees (BSP = Binary Space Partitioning)– KD-Trees

• Assignment of objects to partitions• Collision detection then becomes

1) determine in which partition the object is2) test only objects in the same partition

• Good for static scenes, otherwise the hierarchyhas to be re-build

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Regular Grid• Span course grid over the domain • Find cells in which the objects reside

• Test if one cells contains more than one object• Not really a hierarchy (one level)

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Octrees

– Recursive regular subdivision of space into 8 subspaces• One node is split into 8 child nodes

Balanced octree - grid

Adaptive quadtree

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Examples

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Bsp-Trees

– Computational representation of space• Search structure and representation of geometry

– Generalization of binary search trees for dim>1– Search complexity to find spatial relationships

between n polygons within O(n log n)– Recursive space partitioning by means of arbitrarily

positioned partitioning planes

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Bsp-Trees (Binary Space Partitioning)

– Every cell is a convex polyhedron

A

C

D

B

P1

P2

P3

P2

P1

P3

A C B D

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Bsp-Tree example

– Inter-object partitioning– Binary tree of lines in 2D

A

B C

D

A

B

C

D Partitioning Tree

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Characteristics of Bsp-Trees

– Transformation of object = transformation of tree– Intra-object relationships remain static for solid

objects– Merging with other trees easy to do– Objects in one halfspace cannot intersect objects in

the corresponding other halfspace• Accelerates intersection test between objects

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Constructing Bsp-Trees

– Elementary operation is recursive subdivision• Split convex region into two convex subregions• Use hyperplanes as cutting primitives

R+

R-

Hyperplane

R

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Bsp-Tree construction

– Different orderings of faces to use as hyperplanes result in different trees

• Greedy approach (decisions for each step based on what seems optimal) not always applicable

– Good Bsp-Tree represents the model as sequence of approximations

• Pruning yields different resolutions of the model

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Bsp-Tree construction

– Bsp-Trees only perform good if geometric features are local

• Is true most of the time• Then, a significant subset of space can be eliminated

– Low cost (short paths) for reaching high probability regions

• Similar to Huffman coding

– Probability for ´in a region´ is proportional to the size of the region

• p+ = vol(tree.posSubspace) / vol(tree)• p- = vol(tree.negSubspace) / vol(tree)

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Collison test for particles in BSP-tree

– Test, in which node the particle is located– Traverse tree until leafs– Collision, if at least one filled leaf is hit

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Collision test for particles in BSP-tree

– Clip path line between 2 particle locations at separating planes

– Test all in-between time steps– Collision will be detected independent of size of time step

t0

t0 + t t0 + t

t0

collision detectedCollision not detected

computer graphics & visualization

Simulation and Animation – SS07Jens Krüger – Computer Graphics and Visualization Group

Spatial hierarchies• Collision test for particles with extend

– Offset on surfaces (level planes)– Different offsets for different moving objects– Construction of different BSP-trees

Problem:Distance too large

Recommended