Collision handling: detection and response

Slides:



Advertisements
Similar presentations
Everything you ever wanted to know about collision detection
Advertisements

2.4. Primitive Tests - Closest point
2.5. B ASIC P RIMITIVE I NTERSECTION Details of common forms of primitive intersection test.
COMP 175 | COMPUTER GRAPHICS Remco Chang1/6103b – Shapes Lecture 03b: Shapes COMP 175: Computer Graphics February 3, 2015.
Intersection Testing Chapter 13 Tomas Akenine-Möller Department of Computer Engineering Chalmers University of Technology.
CSE 681 Bounding Volumes. CSE 681 Bounding Volumes Use simple volume enclose object(s) tradeoff for rays where there is extra intersection test for object.
Chapter 4.2 Collision Detection and Resolution. 2 Collision Detection Complicated for two reasons 1. Geometry is typically very complex, potentially requiring.
Collision Detection CSCE /60 What is Collision Detection?  Given two geometric objects, determine if they overlap.  Typically, at least one of.
Collision Detection and Resolution Zhi Yuan Course: Introduction to Game Development 11/28/
Computer graphics & visualization Collisions. computer graphics & visualization Simulation and Animation – SS07 Jens Krüger – Computer Graphics and Visualization.
Geometry Primer Lines and rays Planes Spheres Frustums Triangles Polygon Polyhedron.
Extended Gaussian Images
Informationsteknologi Wednesday, November 7, 2007Computer Graphics - Class 51 Today’s class Geometric objects and transformations.
Advanced Computer Graphics Spring 2014
Advanced Computer Graphics Spring 2014 K. H. Ko School of Mechatronics Gwangju Institute of Science and Technology.
A Fast Algorithm for Incremental Distance Calculation Paper by Ming C. Ling and John F. Canny Presented by Denise Jones.
CS447/ Realistic Rendering -- Solids Modeling -- Introduction to 2D and 3D Computer Graphics.
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 Basic 3D collision detection We want to know if objects have touched Objects are considered to.
1Notes. 2Heightfields  Especially good for terrain - just need a 2d array of heights (maybe stored as an image)  Displacement map from a plane  Split.
Collision Detection CSE 191A: Seminar on Video Game Programming Lecture 3: Collision Detection UCSD, Spring, 2003 Instructor: Steve Rotenberg.
Chapter 4.2 Collision Detection and Resolution. 2 Collision Detection Complicated for two reasons 1. Geometry is typically very complex, potentially requiring.
1 Geometry A line in 3D space is represented by  S is a point on the line, and V is the direction along which the line runs  Any point P on the line.
OBBTree: A Hierarchical Structure for Rapid Interference Detection Gottschalk, M. C. Lin and D. ManochaM. C. LinD. Manocha Department of Computer Science,
Complex Model Construction Mortenson Chapter 11 Geometric Modeling
CSE 681 Object Intersection. CSE 681 Object Representation Implicit forms F(x,y,z) = 0 Explicit forms Analytic form x = F(y,z) testing generating Parametric.
Collision Detection David Johnson Cs6360 – Virtual Reality.
Introduction to 3D Graphics John E. Laird. Basic Issues u Given a internal model of a 3D world, with textures and light sources how do you project it.
CSE 681 Ray Tracing Implicit Surfaces. CSE 681 Overview Similar to CSG –Combine primitive objects to form complex object Primitives are “density fields”
Computer graphics & visualization Collision Detection – Narrow Phase.
Computational Geometry
Week 13 - Wednesday CS361.
Interaction and Normals Intro to Programming in 3D Applications Lecture 20.
Computer Graphics: Programming, Problem Solving, and Visual Communication Steve Cunningham California State University Stanislaus and Grinnell College.
CS 450: Computer Graphics REVIEW: OVERVIEW OF POLYGONS
7.1 Scalars and vectors Scalar: a quantity specified by its magnitude, for example: temperature, time, mass, and density Chapter 7 Vector algebra Vector:
Unit 5 Vocab By: Mika Hamady. Acute Angle Definition: An acute angle is an angle that is less then 90 degrees. Examples: 1.A 43 degree angle is acute.
CSE 381 – Advanced Game Programming Quickhull and GJK.
Part 6: Graphics Output Primitives (4) 1.  Another useful construct,besides points, straight line segments, and curves for describing components of a.
Spaces 1D, 2D, and 3D Point Line Plan Points/Vectors A point p = (x,y,z) is also the vector p Vector Operation The Length of the vector v Normalization.
Computer Animation Rick Parent Computer Animation Algorithms and Techniques Collisions & Contact.
Section 8.4 Nack/Jones1 Section 8.4 Polyhedrons & Spheres.
Week 13 - Monday.  What did we talk about last time?  Exam 2!  Before that…  Polygonal techniques ▪ Tessellation and triangulation  Triangle strips,
PRESENTED BY – GAURANGI TILAK SHASHANK AGARWAL Collision Detection.
CIS 350 – I Game Programming Instructor: Rolf Lakaemper.
Vertices, Edges and Faces By Jordan Diamond. Vertices In geometry, a vertices is a special kind of point which describes the corners or intersections.
Chapter Area, Pythagorean Theorem, and Volume 14 Copyright © 2013, 2010, and 2007, Pearson Education, Inc.
1 11. Polygons Polygons 2D polygons ( 다각형 ) –Polygon sides are all straight lines lying in the same plane 3D polyhedra ( 다면체 )  chap. 12 –Polyhedra.
Inelastic Collision An elastic collision is an encounter between two bodies in which the total kinetic energy of the two bodies after the encounter is.
3D Object Representations 2011, Fall. Introduction What is CG?  Imaging : Representing 2D images  Modeling : Representing 3D objects  Rendering : Constructing.
Acute angle: An angle with a measure less than 90º.
CSE 681 Object Intersection. CSE 681 Object Representation Implicit forms F(x,y,z) = 0 Explicit forms Analytic form x = F(y,z) testing generating Parametric.
Vocabulary for the Common Core Sixth Grade.  base: The side of a polygon that is perpendicular to the altitude or height. Base of this triangle Height.
Distance Formulas: Number Line:  b-a  for a and b the coordinates of the points Plane: Exercises: 1.Find the distance AB if a = -3 and b=7 2.Find the.
Properties of Transformations. Translate Figures and Use Vectors Translation: moves every point of a figure the same distance in the same direction Image:
Polyhedra and Prisms.
Surface Area and Volume
Collision Detection Spring 2004.
3D Object Representations
Parts of these slides are based on
Chapter 4.2 Collision Detection and Resolution
Collision handling: detection and response
2.5. Basic Primitive Intersection
Object Intersection CSE 681.
Chapter 9: Linear Momentum and Collisions
Vertical Angles Vertical angles are across from each other and are created by intersecting lines.
Computer Animation Algorithms and Techniques
14 Chapter Area, Pythagorean Theorem, and Volume
Game Programming Algorithms and Techniques
David Johnson Cs6360 – Virtual Reality
GPAT – Chapter 7 Physics.
Presentation transcript:

Collision handling: detection and response CSE 3541 Matt Boggus

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

Geometric modeling primitives Point Line segment Polygon

Terminology – convex and concave polygons

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.

Convex and concave – interior angles

Polygon triangulation split into a set of convex polygons

Types of equations Explicit y = f(x) Implicit f(x,y) = 0 Ex: y = mx + b Implicit f(x,y) = 0 Ex: x2 + y2 – 1 = 0 Given values for (x,y), say x = a and y = b, compute f(a,b) = c c > 0, then (a,b) is “outside” shape f c = 0, then (a,b) is on the boundary/surface of shape f c < 0, then (a,b) is “inside” shape f Parametric form (x,y) = (f(u),g(u)) Ex: x = f(t) = r cos (t) , y = g(t) = r sin (t) Given any value for t parameter, compute a point (x,y) Implicit – good for intersection tests and morphing Parametric – good for generating points and polygons

Parametric line equation P(t) = P0 + t V P0 is point on line V is direction (or slope) of line On line segment with P1, t ranges from (0,1) x = P0.x + t * (P1 – P0).x y = P0.y + t * (P1 – P0).y

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

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

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

Line intersection – visual example Example drawn on board

Point in polygon – ray test

Ray test special cases

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

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

Polygon Intersection Contained vertex Intersecting edges

Polygon intersection – vertex + edges

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

Surface/Polygon normals Images from http://en.wikipedia.org/wiki/Normal_(geometry)

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

Collision detection: time of impact P(ti) P(ti+1) 2 options Consider collision at next time step Compute fractional time at which collision actually occurred Tradeoff: accuracy v. complexity

3D object collision detection

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

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

Bounding objects Sphere Axis aligned bounding box Oriented bounding box

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

Axis aligned bounding box

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

Bounding sphere

Bounding sphere

Bounding sphere

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

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

Convex hull

Convex hull

Convex hull

Convex hull

Convex hull

Convex hull

Convex hull

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

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

AABB vs. AABB

AABB vs. AABB

Oriented bounding boxes and arbitrary polygons Separating axis theorem http://gamedev.tutsplus.com/tutorials/implementation/collision-detection-with-the-separating-axis-theorem/ http://www.sevenson.com.au/actionscript/sat/ http://www.metanetsoftware.com/technique/tutorialA.html

Sphere vs. AABB

Sphere vs. AABB – clamping

Sphere vs. AABB – closest point

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

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

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

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

Collision detection speedup

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++

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

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

HBV example

HBV example

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

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

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

Collision response

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

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

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

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: http://mathworld.wolfram.com/Reflection.html

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: http://www.euclideanspace.com/physics/dynamics/collision/index.htm http://www.metanetsoftware.com/technique/tutorialA.html http://en.wikipedia.org/wiki/Elastic_collision

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

Collision response: damped Damping factor = 0.8

Collision response – penalty method

Collision response: penalty

Additional issues Adding physics for rotation Handling multiple collisions Resting contact