Docsity

Collision Detection Algorithms for Polygonal Objects, Study notes of Computer-Aided Analysis of Machine Dynamics

Partial preview of the text

Download Collision Detection Algorithms for Polygonal Objects and more Study notes Computer-Aided Analysis of Machine Dynamics in PDF only on Docsity!

Collision Detection for Polygonal Objects

given global location  ri and attitude  (^) i for all bodies at time t

given s (^) i ' Pfor all vertices on all bodies (constants)

polygons must not be self-crossing

polygons must not have holes

r (^) iP 1

 ri P 2

 ri P^3

 ri P^4

x (^) i'

y (^) i'

r (^) jP 2

 rj P 3

r (^) jP 1

x (^) j'

y (^) j'

Bounding Circle - quick check

before the simulation, find maximum radius  (^) i max norms (^) i'Pover all vertices for each

body (one constant scalar value per body that may be computed a priori)

at each time t, compute center distance c (^) ij  norm r (^) i  rjbetween all pairs of bodies

if c (^) ij ijthen no collision can occur between bodies i and j

if c (^) ij ijthen bodies i and j are candidates for collision detection

does not require calculation of  ri P for any vertices on any bodies

works best for centroidal origins and objects with low aspect ratios

x (^) i'

y (^) i'

i

c ij

x (^) j'

y (^) j'

j

Point in Polygon

must check if any vertices on body j are inside body i AND check if any vertices on body i are inside body j

computational complexity O(n^2 )for convex objects and O(2n^2 ) for ray casting

point in polygon does not always work for thin bodies (may need edge intersection)

x (^) i'

y (^) i'

x (^) j' y (^) j'

x (^) i'

y (^) i'

x (^) j'

y (^) j'

Point in Polygon – Convex Objects

vertices must be ordered CW around polygon

at each time t, calculate   P ri for all points on all bodies that are candidates for collision

select one point  r (^) jPon body j and test if it is to the right or to the left of edge  ri Q   ri Pon

body i

external normal  nˆ^ will be parallel to  R    ri Q  ri P

if   r  r  R    r  r  0 P i

Q i

PT i

P j ^   , the point is to the left of the edge, is outside the polygon and the search across edges may be terminated for that point

if   r  r  R    ri Q  ri P 0 PT i

P j ^   , the point is on the edge and may be inside the polygon

if   r  r  R    ri Q  ri P 0 PT i

P j ^   , the point is to the right of the edge and may be inside the polygon

expand                  P i

Q i

P i

P j

P i

Q i

P i

P j

P i

Q i

PT i

P rj r R r  r  y y x x x x y y

point  rj Pmust be to the right of ALL edges to be inside body i

computational complexity O(n^2 /2)

does not work for bodies with concavities or holes

 r (^) jP  nˆ

  P ri

x (^) i'

y (^) i'

r (^) iQ

r (^) jP

 rj P

x (^) i'

y (^) i'

Edge Intersection

must check every edge on body i for intersection with every edge on body j

        ^    

P j

Q j j

P j

P i

Q i i

P ri  d r  r  r d r  r intersect if 0  di  1 and 0 dj  1

           j P  i P

j

P i j

Q j

P i

Q i (^) d r r

d r r r r   

 jQ jP iQ iP  iQ iP jQ jP

P i

P j

P j

Q j

P i

P j

P j

Q j i x x y y x x y y

x x y y y y x x d     

 jQ jP iQ iP  iQ iP jQ jP

P i

P j

P i

Q i

P i

P j

P i

Q i j x x y y x x y y

x x y y y y x x d     

if denominator = 0, segments are parallel

must check if they are coincident  r   r  R    ri Q  ri P 0

P T i

P j   

expand  y j PyiPx iQxiP x jPxiP yiQyiP  0

computational complexity O(n^2 )

edge intersection does not always work if one body is completely inside the other (may need point in polygon)

r jQ

 rj P

r iQ

 ri P

di

dj

Separating Axis Theorem (SAT)

vertices must be ordered CW around polygon

before the simulation, select one edge s (^) i ' Q s (^) i'Pon body i and compute external normal

 nˆ^ unit R  s (^) i ' Qs (^) i'P

compute the projection R p (^) i for all points   R s (^) i ' onto the normal and store the minimum value MIN p (^) i (one scalar constant per edge that may be computed a priori)

         (^) i Q  (^) iP P T i

R i

R p (^) i  s ' s ' unit R s ' s '

at each time t, calculate  ri P for all points on all bodies that are candidates for collision

select edge  ri Q   ri Pon body i and compute external normal n ˆ^  unit R    ri Q  ri P

called the separating axis

select point   P rj on body j and compute its projection P p (^) j onto the separating axis

         (^) i Q  i P P T i

P j

P p (^) j  r r norm R r r

compute the projection p (^) jPonto the separating axis for all other points on body j and store the

maximum p (^) jMAX and minimum p (^) jMINvalues

check for overlap of projections onto the separating axis

 0 pjMIN  (^) ANDp (^) jMAXpiMIN

if false, the projections do not overlap, there can be no collision and the test may be terminated

if true, the projections overlap and must continue checking all other edges  ri Q ri P

does not work for bodies with concavities or holes

very similar to convex body point in polygon however do not need to check (i in j) and (j in i)

computational complexity O(n^2 /2)

Classification of Contacts

Body i vertices in j

Body i edge intersections

Body j vertices in i

Body j edge intersections

Contact points

vertex-edge 0 1 1 2 3 edge-edge 1 2 1 2 4 multiple vertex-edge 0 1 ≥ 2 2 5 multiple edge-edge 1 2 ≥ 2 2 5

i

j

i

j

i

j

i

j

vertex-edge

edge-edge

multiple vertex-edge multiple edge-edge

Interpolating Time of Collision (vertex-edge)

given candidate vertex  rj Pt on body j that collides with body i at time t

given candidate edge  ri Qt   ri Pt on body i that has two edge intersections with body j at time t

must know position and velocity for all three points at time t-h (time step h)

Constant velocity predictor

predict position of all three points at local time 0  thusing vales from t-h

 r (^) i P   ri Pt h ri Pt (^) h t

 r  r  r  t Q i th

Q i th

Q i ^     

 r (^) j P   rj Pt (^)  h rj Pt (^) h t

when vertex  r (^) jPintersects edge  ri Q   ri P  r   r  R    ri Q  ri P 0 P T i

P j   

substituting position equations and collecting similar terms

a  t b t c 0 2     

          (^) i Q (^) th  i Pth P T i th

P a  rj (^) th  r  R r   r 

                      (^) i Qt (^) h  i Pth P T i th

P jth

P i th

Q i th

P T i th

P b  rj (^) t hr  R r  r   r  r  R r   r 

          (^) i Qt (^) h  i Pth P T i th

P c  rj (^) t hr  R r  r 

 ri Q r (^) iP

r (^) jP

         (^) i Qt (^) h  i Pth P T i th

P c 0  rj t hr  R r  r  (same as c above)

use root finding algorithm for t (e.g. MATLAB “roots”)

must check 0  thand it must not be imaginary

Three-dimensional Collision Detection

Quick checks

Bounding spheres and AABB both work well

Point in polyhedron – convex bodies

at each time t, calculate   P ri for all points on all bodies that are candidates for collision

select one point  r (^) jPon body j and test if it is outside or inside a facet on body i defined by

external normal  nˆ and any vertex r (^) i Pon the facet

if   r  r   nˆ 0 PT i

P j ^  , the point is outside the polyhedron and the search across facets may be terminated for that point

if   r  r   nˆ 0 PT i

P j ^  , the point is on the facet and may be inside the polyhedron

if   r  r   nˆ 0 PT i

P j ^  , the point is inside the facet and may be inside the polyhedron

point  rj Pmust be inside of ALL facets to be inside body i

point in polygon does not always work for thin bodies (may need edge intersection)

Point in polyhedron – ray casting

at each time t, calculate  ri P for all points on all bodies that are candidates for collision

select one point  r (^) jPon body j and test if it is inside body i

cast an infinite ray in any direction from ^  P rj and compute intersections with all facets on body i

if there are an even number of intersections, r (^) jPis not inside body i

if there are an odd number of intersections, r (^) j Pis inside body i

works for concavities, holes and self-crossing and is independent of CW versus CCW boundary

Handling Collision

Physical simulators differ in the way they react to a collision. Some use the softness of the material to calculate a force, which will resolve the collision in the following time steps like it is in reality. Due to the low softness of some materials this is very CPU intensive.

Other simulators estimate the time of collision by interpolation, roll back the simulation, and calculate the exact time of collision. This may require several iterations.

After an inelastic collision, special states of sliding are often imposed. For example, an open pin-in-slot constraint is added for a vertex-edge intersection to force that vertex to slide on the edge rather than penetrate it. The Open Dynamics Engine uses this approach.