Collision handling: detection and response Collision handling overview Detection Discrete collision detection Convex polygon intersection test General polygon intersection test Continuous collision detection Vertex‐triangle test Edge‐edge test R Response Kinematic response Penalty method Discrete Collision Handlingg • Run Run the simulation from t to t+1, without the simulation from t to t+1 without considering collision • Check if any intersection happens at t+1 Check if any intersection happens at t+1 • If so, remove it Geometric Modeling Primitives g • Point • Line segment • Polygon Terminology – convex and concave polygons l Edge Test Decides convex/concave Always on one side Always on one side Not always on one side Not always on one side Works same for convex/concave polyhedra (always on on side of the polygonal face?) (always on on side of the polygonal face?) An important property of Convex polygons! l ! Initial Pair You can always find the closest vertex pair by gradually moving one vertex at each time! An important property of Convex polygons! l ! You can always find the closest vertex pair by gradually moving one vertex at each time! An important property of Convex polygons! l ! You can always find the closest vertex pair by gradually moving one vertex at each time! An important property of Convex polygons! l ! You can always find the closest vertex pair by gradually moving one vertex at each time! An important property of Convex polygons! l ! You can always find the closest vertex pair by gradually moving one vertex at each time! An important property of Convex polygons! l ! You can always find the closest vertex pair by gradually moving one vertex at each time! An important property of Convex polygons! l ! No more improvement, done! You can always find the closest vertex pair by gradually moving one vertex at each time! An important property of Convex polygons! l ! • The computational cost depends on the initial pair – Worst case O(N) – Best case O(1)! B t O(1)! • In animation, since we can keep the pair over time and the object movement within a time step is and the object movement within a time step is small, the initial pair is often good! – O(1) • Problem: not everything is convex – Solution: decompose them into convex components p p – Doesn’t always work General Polygon Intersection Tests • To To test whether two polygons intersect, we can test whether two polygons intersect, we can test whether any vertex is inside of another Inside/Outside Test • To test whether a point is within a polygon/polyhedron shoot a ray and count the polygon/polyhedron, shoot a ray and count the intersections! • Odd => inside; even =>outside Odd => inside; even =>outside 3 intersections ‐> inside d Inside/Outside Test • To test whether a point is within a polygon/polyhedron shoot a ray and count the polygon/polyhedron, shoot a ray and count the intersections! • Odd => inside; even =>outside Odd => inside; even =>outside 1 intersection ‐> inside Inside/Outside Test • To test whether a point is within a polygon/polyhedron shoot a ray and count the polygon/polyhedron, shoot a ray and count the intersections! • Odd => inside; even =>outside Odd => inside; even =>outside 4 intersection > outside 4 intersection ‐> outside Inside/Outside Test • To test whether a point is within a polygon/polyhedron shoot a ray and count the polygon/polyhedron, shoot a ray and count the intersections! • Odd => inside; even =>outside Odd => inside; even =>outside 0 intersection ‐> outside Inside/Outside Test • • • • Doesn’t always work… intersections but still inside? 2 intersections but still inside? This is called a degenerate case. Solutions? Try some other directions Solutions? Try some other directions 2 intersections??? Problem 1 (in 3D)? ( ) Collision can happen even there is no vertex inside of pp the other polyhedron. Called edge‐edge colllision The solution requires complex intersection tests. We skip it here… Discrete Collision Handlingg • Run Run the simulation from t to t+1, without the simulation from t to t+1 without considering collision • Check if any intersection happens at t+1 Check if any intersection happens at t+1 • If so, remove it Problem 2? • Discrete collision handling has a tunneling artifact. No intersection at t or t , but intersection happens in • No intersection at t or t+1, but intersection happens in‐ between. Time t Time t Time t+1 Time t+1 Problem 3? • To do inside/outside test, the object must be closed. • In other words, it has an area (or volume). • How do I know if two curves/surfaces are intersecting? – Knowing the location of the intersection is not sufficient! Solution • We don’t just check whether intersection happens at t or t+1. • We check if any intersection happens between t and t+1. ( pp g • This is called continuous collision detection (opposing to discrete collision detection). For example: Vertex‐Triangle For example: Vertex Triangle Test Test • Four points – P0(t)=P0+tV0; P1(t)=P1+tV1; P2(t)=P2+tV2; P3(t)=P3+tV3 • Intersection happens when they are co‐planar pp y p – (P1(t)‐P0(t))(P2(t)‐P0(t))×(P3(t)‐P0(t))=0 • Once you find t, verify if P y , y 0((t) is within the triangle. ) g P2 P1 P0 P3 For example: Edge‐EdgeTest For example: Edge EdgeTest • Four points – P0(t)=P0+tV0; P1(t)=P1+tV1; P2(t)=P2+tV2; P3(t)=P3+tV3 • Intersection happens when they are co‐planar – (P1(t)‐P0(t))(P2(t)‐P0(t))×(P3(t)‐P0(t))=0 • Once you find t, verify if they do intersect! Once you find t, verify if they do intersect! P2 P1 P0 P3 Polygon and polyhedra complexity Polygon and polyhedra complexity How many edges? How many points? Bounding objects Bounding objects • Sphere • Axis aligned bounding box Axis aligned bounding box • Oriented bounding box Bounding volume construction Bounding volume construction • Given Given a set of points as input, can we 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 Axis aligned bounding box (AABB) Axis aligned bounding box (AABB) Bounding sphere Bounding sphere Bounding sphere Bounding sphere Bounding sphere Bounding sphere Bounding sphere Bounding sphere Convex Hull Convex Hull Best fit convex polyhedron to concave polyhedron but takes some (one-time) (one time) computation 1. Find highest vertex, V1 2. Find remaining vertex that minimizes angle with horizontal plane through point. Call C edge L 3. Form plane with this edge and horizontal line perpendicular to L at V1 4. Find remaining vertex that for triangle that minimizes angle with this plane. Add this triangle to convex hull, mark edges as unmatched t h d 5. For each unmatched edge, find remaining vertex that minimizes angle with the plane g triangle g of the edge’s 6. 3D convex hull is more complex… Convex hull Convex hull Convex hull Convex hull Convex hull Convex hull Convex hull 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 planepairs i Is a vertex between each pair? d 2 N P d1 Sphere vs. Sphere Sphere vs. Sphere Compare distance (p1,p2) to r1+r2 distance(p1,p2)2 to (r1 + r2)2 AABB vs. AABB AABB vs. AABB AABB vs. AABB AABB vs. AABB Oriented bounding boxes and arbitrary polygons l • Separating axis theorem Separating axis theorem – http://gamedev.tutsplus.com/tutorials/implement ation/collision detection with the separating axis ation/collision‐detection‐with‐the‐separating‐axis‐ theorem/ – http://www.sevenson.com.au/actionscript/sat/ – http://www.metanetsoftware.com/technique/tut orialA.html Hierarchical bounding volumes Hierarchical bounding volumes Approximating polyhedra with spheres for time‐critical collision detection, by Philip M. Hubbard HBV example HBV example HBV example HBV example HBV example HBV example Spatial subdivision – grid ( (quadtrees and octrees) d d ) Spatial subdivision – binary space partitioning ii i Collision response Collision response Collisions: physics review Collisions: physics review • Momentum p mv • In a closed system, momentum is conserved p mv m'v' • After a collision, the sum of all momentums is the same as the sum of all momentum before the collision Collision types Collision types Elastic collisions – no loss of kinetic energy (e g deformations heat) energy (e.g. deformations, heat) Kinetic energy Inelastic collisions – loss of kinetic energy kinetic energy 1 2 E mv 2 Elastic collision with stationary object: h i horizontal and vertical walls/planes l d i l ll / l • For vertical wall/boundary o e ca a /bou da y – Negate x component of velocity – Preserve y component of P f velocity • Ex: v0 = (3,‐3) ; v = (‐3,‐3) ( , ); ( , ) • For horizontal walls/boundaries – Preserve x – Negate y Elastic collision with stationary object: angled walls/planes l d ll / l • 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 Vector/direction is parallel to n – Scalar/magnitude is in opposite direction of n; (v * n) < 0 • w w = v v–u • Reflected velocity: v’ = w – u Inelastic Collisions Coefficient of restitution ratio of velocities before and after collision (dampen the resulting velocity) l it ) Objects stick together, momentum is conserved Collision response – penalty method
© Copyright 2025 Paperzz