Presentation is loading. Please wait.

Presentation is loading. Please wait.

Collision handling: detection and response

Similar presentations


Presentation on theme: "Collision handling: detection and response"— Presentation transcript:

1 Collision handling: detection and response
CSE 3541/5541 Matt Boggus

2 Collision handling overview
Point collision detection Line segment and ray collision detection Polyhedron-polyhedron collision detection Bounding volume test Vertex inside polyhedron test Concave case Convex case Edge-face intersection test detection Kinematic response Penalty method response

3 Geometric modeling primitives
Point Line segment Polygon

4 Terminology – convex and concave polygons
There can be some “weird” cases that generally do not occur in practice, see more at

5 Convex and concave – line test
For any two points within a polygon, the line segment they form is contained within the polygon if it is convex, otherwise it is concave.

6 Convex and concave – interior angles

7 Polygon triangulation split into a set of convex polygons

8 Generic collision detection test
Given two objects, the objects are either colliding or not colliding if( objectsCollide ) { collision response } Ex: two 2D points, P and Q P.x == Q.x && P.y == Q.y (P.x – Q.x < errorThreshold) && (P.y – Q.y < errorThreshold) In general, set equations equal to each other

9 Types of equations Explicit y = f(x) Implicit 0 = f(x,y)
Ex: y = 2x+5 Implicit 0 = f(x,y) Ex: x2 + y2 – 1 = 0 Given some point P = (a,b), compute f(a,b) = c c > 0, then P is outside of circle c = 0, then P is on boundary of circle c < 0, then P is inside circle Parametric (x,y) = (f(t),g(t)) Ex: x = cos (t), y = sin (t) Given a value for t, compute a point (x,y) = P P is on boundary of circle Note: shapes other than circles can be defined too Implicit – good for intersection tests Parametric – good for generating points

10 Parametric line equation
P(t) = P0 + t V P0 is point on line V is direction (or slope) of line On line segment ending at P1, t ranges from (0,1) Can also be expressed in (x,y) components x = P0.x + t * (P1.x – P0.x) y = P0.y + t * (P1.y – P0.y) Stress this

11 Point on a line segment Given (x,y), is it on a line segment (P1 to P0)? x = P0.x + tx * (P1.x – P0.x) y = P0.y + ty * (P1.y – P0.y) Plug in x, y, P0, P1, solve for tx and ty On the segment if 0 ≤ tx = ty ≤ 1

12 Examples P0 = (0,0) P1 = (1,1) P = (0.5, 0.5) P = (-1, -1) P = (2, 2)
Examples drawn on board

13 Line intersection – two equations
Pa = P0 + ta (P1 – P0) Pb = P2 + tb (P3 – P2) Set them equal, solve for ta and tb Note that these are vector equations, not scalars Line segment intersection if 0 <= ta <= 1, and 0 <= tb <= 1

14 Line intersection – visual example
Example drawn on board

15 Point in polygon – ray test

16 Ray test special cases

17 Point in convex polygon
(y - y0) (x1 - x0) - (x - x0) (y1 - y0) > 0, point is to the left of the line < 0, point is to the right of the line = 0, point is on the line “sided” test, call back to implicit equations (x,y) is the point to test (x0,y0) and (x1,y1) are two points defining an edge of the polygon

18 Point in convex polygon
(y - y0) (x1 - x0) - (x - x0) (y1 - y0) For (3,1): (1)(5) – (3)(0) = 5 For (3,0): (0)(5) – (3)(0) = 0 For (3,-1): (-1)(5) – (3)(0) = -5

19 Polygon Intersection Contained vertex Intersecting edges

20 Polygon intersection – vertex + edges

21 Collision detection: point-ground plane
p = (x, y, z)

22 Surface/Polygon normals
Images from

23 Collision detection: point-arbitrary plane
p = (x, y, z) N = (a, b, c) N Terms: p = point N = normal vector D = distance from origin

24 Collision detection: time of impact
P(ti) P(ti+?) P(ti+1) For computing the fractional time, consider line segment – plane intersection test generating multiple sample points at different fractional time values, select the one closest to E(p) = 0 2 options -Resolve collision based on new position, P(ti+1) -Compute fractional time at which collision actually occurred, resolve collision based on that position, P(ti+?) Tradeoff: accuracy v. computational cost

25 3D object collision detection

26 Collision detection: polyhedra
Order tests according to computational complexity and power of detection 1. test bounding volumes for overlap 2. test for vertex of one object inside of other object 3. test for edge of one object intersecting face of other object

27 Polygon and polyhedra complexity
How many edges? How many points?

28 Bounding objects Sphere Axis aligned bounding box
Oriented bounding box

29 Bounding volume construction
Given a set of points as input, can we automatically create bounding volumes Axis aligned bounding box Sphere Convex hull

30 Axis aligned bounding box

31 Axis aligned bounding box
Loop over all vertices to find min and max x and y coordinates, these define the min and max planes of the box

32 Bounding sphere

33 Bounding sphere

34 Bounding sphere

35 Bounding sphere Determine sphere center – use the midpoint of maximally separated pair OR the centroid (average x, average y, average z) May also choose to set initial radius Loop over all points, altering the sphere to fit the each point

36 Convex Hull Best fit convex polyhedron to concave polyhedron but takes some (one-time) computation Find highest vertex, V1 Find remaining vertex that minimizes angle with horizontal plane through point. Call edge L Form plane with this edge and horizontal line perpendicular to L at V1 Find remaining vertex that for triangle that minimizes angle with this plane. Add this triangle to convex hull, mark edges as unmatched For each unmatched edge, find remaining vertex that minimizes angle with the plane of the edge’s triangle

37 Convex hull

38 Convex hull

39 Convex hull

40 Convex hull

41 Convex hull

42 Convex hull

43 Convex hull

44 Bounding Slabs For better fit bounding polyhedron: use arbitrary (user-specified) collection of bounding plane-pairs Is a vertex between each pair?

45 Sphere vs. Sphere Compare distance (p1,p2) to r1+r2

46 AABB vs. AABB

47 AABB vs. AABB

48 Oriented bounding boxes and arbitrary polygons
Separating axis theorem

49 Sphere vs. AABB

50 Sphere vs. AABB – clamping

51 Sphere vs. AABB – closest point

52 Collision detection: polyhedra
1. test bounding volumes for overlap 2. test for vertex of one object inside of other object 3. test for edge of one object intersecting face of other object Now consider #2 and #3

53 Collision detection: polyhedra
Intersection = NO For each vertex, V, of object A if (V is inside of B) intersection = YES For each vertex, V, of object B if (V is inside of A) intersection = YES A vertex is inside a convex polyhedron if it’s on the ‘inside’ side of all faces A vertex is inside a cancave polyhedron if a semi-infinite ray from the vertex intersects an odd number of faces

54 Collision detection: polyhedra
Edge intersection face test Finds all polyhedral intersections, but is the most expensive test: for all faces (i) for all edges (j) test face i for intersection with edge j Set plane equation equal to line equation (this generates a point) Test point to determine if it is inside the polygon face If vertices of edges are on opposite side of plane of face Calculate intersection of edge with plane Determine if that point of intersection is inside the face

55 Collision response

56 Collisions: physics review
Momentum In a closed system, momentum is conserved After a collision, the sum of all momentums is the same as the sum of all momentum before the collision

57 Collision types Inelastic collisions – loss of kinetic energy
Elastic collisions – no loss of kinetic energy (e.g. deformations, heat) Inelastic collisions – loss of kinetic energy Kinetic energy

58 Elastic collision with stationary object: horizontal and vertical walls/planes
For vertical wall/boundary Negate x component of velocity Preserve y component of velocity Ex: v0 = (3,-3) ; v = (-3,-3) For horizontal walls/boundaries Preserve x Negate y

59 Elastic collision with stationary object: angled walls/planes
Still split velocity vector into components Now with respect to the normal (n) of the wall u = (v * n / n * n) n Note: * is dot product Vector/direction is parallel to n Scalar/magnitude is in opposite direction of n; (v * n) < 0 w = v – u Reflected velocity: v’ = w – u For more on this topic, check out:

60 Penalty method normal spring force

61 Collision response: penalty

62 Collision response: damped
Damping factor = 0.8

63 Other object vs. plane ideas
normal old velocity Some ideas include, but are not limited to: Position clamping Return to previous position distance from plane new velocity

64 Elastic collision with movable object
Determine separating plane/line Split momentum into components parallel and orthogonal to plane/line Set object momentum using components More details and examples at:

65 Other object vs. object ideas
Some ideas include, but are not limited to: Averaging velocities Swap velocities v1

66 Inelastic Collisions Coefficient of restitution
ratio of velocities before and after collision (dampen the resulting velocity) Objects stick together, momentum is conserved

67 Additional slideS

68 Collision detection speedup

69 Particle collision detection loop
ArrayList Particles = new ArrayList(); Particle p; Particles.Add(p); void HandleAllParticleCollisions(){ for(int i=0; i < Particles.Count; i++){ for(int j ) { // test Particles i and j for collision } =i+1 j < Particles.Count; j++

70 Collision detection speedup
Two approaches Bound the object Bound the space the object is contained in

71 Hierarchical bounding volumes
Tree of bounding volumes Approximating polyhedra with spheres for time-critical collision detection, by Philip M. Hubbard

72 HBV example

73 HBV example

74 HBV example Only test branches in the tree where there were collisions
If a leaf bounding volume intersects, then the two objects intersect

75 Spatial subdivision – grid (quadtrees and octrees)
Each grid cell has a list of objects in it (objects may be in multiple grid cells) Iterate over grid cells, checking for collisions between all objects in the current grid cell and those of its neighbors

76 Spatial subdivision – binary space partitioning
Instead of regularly sampling space, divide it with planes

77 Collision detection: swept volume
Time & relative direction of travel sweeps out a volume Only tractable in simple cases (e.g. linear translation) If part of an object is in the volume, it was intersected by object

78 Additional issues Adding physics for rotation
Handling multiple collisions Resting contact


Download ppt "Collision handling: detection and response"

Similar presentations


Ads by Google