Title: INDE 544 Lecture
1INDE 544 - Lecture 11
- Jeffrey J. Berkley, PhD
- Office 208 Sieg Hall
- e-mail jberkley_at_u.washington.edu
2Last Time
- B-Spline Curves
- Brief Overview of NURBS
- Implicit Solid Models
- Translating, Rotating and Scaling Solids
- Boolean Operations with Solids
- Morphing Solids
- Blending Solids
- Rendering Solids
3Collision Detection Background
- The problem of collision detection between moving
objects is fundamental to simulations of the
physical world - Collision detection is an important feature of
robotics, computer-aided design, manufacturing,
animation and computer simulated environments. - Collision detection enables simulation based
design, tolerance verification, engineering
analysis, assembly and dis-assembly, motion
planning, animated figure articulation, task
traing simulation, etc.
4Collision Detection Background
- Collision detection involves contact analysis and
spatial reasoning of static and/or moving
objects. - For many applications, collision detection is
considered a major computational bottleneck.
5Some Examples of Applications
- Robotics Used to help steer the robot away from
surrounding obstacles. - Virtual Prototyping Used to refine designs and
their assembly without producing physical
prototypes. - Virtual Analysis Can be used to simulate things
that might be impractical or too expensive to
conduct in real life, such as automobile crash
testing. - Task Simulation Some tasks can not be practiced
realistically without simulation, such as surgery
and space station repair.
6Types of Collision Detection
- Pair processing vs. N-Body processing
- Static vs. Dynamic
- Rigid vs. Deformable
7Taxonomy of Models
8Polygon Models
- Most commonly used.
- Simple representations and very versatile.
- Hardware-accelerated rendering of polygons is
common.
9Polygon Collision Detection
- Most general class of polygon model can be called
a polygon soup, which is a collection of
polygons that are not geometrically connected and
have no topology available. - If the polygons form a closed manifold, then the
model has a well-defined inside and outside. It
is essentially a proper solid made up of planes. - If the manifold is convex, then this structure
can be efficiently exploited in a collision
detection algorithms.
10Steps for Determining a Collision with a Polygon
- For every point of interest on a moving object,
you should track the current position and the
position one time step back. This will form a
line segment. Tracking should be conducted at a
relatively high update rate (30 Hz if only
visual, 300 Hz for force feedback). - // assume the two points are stored in q13 and
q23, where q1 is the most recent position.
11Steps for Determining a Collision with a Polygon
- Find the equation for a plane that represents the
polygon. The assumption is that the points on
the polygon are ordered counter-clockwise.
Pre-computing these planes is a good idea. - p10mNoden1.x
- p11mNoden1.y
- p12mNoden1.z
- p20mNoden2.x
- p21mNoden2.y
- p22mNoden2.z
- p30mNoden3.x
- p31mNoden3.y
- p32mNoden3.z
12Steps for Determining a Collision with a Polygon
- lengthsqrt(pow(p10-p20,2)pow(p11-p21,2
)pow(p12- p22,2)) - v10(p10-p20)/length
- v11(p11-p21)/length
- v12(p12-p22)/length
- lengthsqrt(pow(p30-p20,2)pow(p31-p21,2
)pow(p32- p22,2)) - v20(p30-p20)/length
- v21(p31-p21)/length
- v22(p32-p22)/length
- plane0 v11v22-v12v21
- plane1 v12v20-v10v22
- plane2 v10v21-v11v20
- plane3 -(plane0p20plane1p21plane
2p22)
13Steps for Determining a Collision with a Polygon
- Find the distance of each point to the plane
formed by your polygon. - dist1plane0q10plane1q11plane2q1
2plane3 - dist2plane0q20plane1q21plane2q2
2plane3 - If the sign of each computed distance is the same
than both points are on the same side of the
plane. Therefore, no collision. - if(dist1dist2gt0) return
14Steps for Determining a Collision with a Polygon
- Find the point where the line segment crosses the
plane. - lambda-dist2/(dist1-dist2)
- q0(q10-q20)lambdaq20
- q1(q11-q21)lambdaq21
- q2(q12-q22)lambdaq22
15Steps for Determining a Collision with a Polygon
- Reduce to a 2D problem to keep it simple
- if((fabs(plane2)gtfabs(plane1))
(fabs(plane2)gtfabs(plane0))) -
- nx0 ny1
-
- else if((fabs(plane1)gtfabs(plane2)
) (fabs(plane1)gtfabs(plane0)
)) -
- nx0 ny2
-
- else
-
- nx1 ny2
-
16Steps for Determining a Collision with a Polygon
- Convert to a triangular coordinate system. Note
that much of this information can be
pre-computed. - x1p3nx x2p2nx x3p1nx
- y1p3ny y2p2ny y3p1ny
- xqnx yqny
- a1x2y3-x3y2 b1y2-y3 c1x3-x2
- a2x3y1-x1y3 b2y3-y1 c2x1-x3
- a3x1y2-x2y1 b3y1-y2 c3x2-x1
- deta1x1b1y1c1
- t1(a1b1xc1y)/det
- t2(a2b2xc2y)/det
- t3(a3b3xc3y)/det
17Steps for Determining a Collision with a Polygon
- If any of the triangular areas are less than zero
or greater than 1, then there is no collision. - if((t1lt1) (t1gt0) (t2lt1) (t2gt0)
(t3lt1) (t3gt0)) - // There has been a collision!
18Example
- See if the has been a collision given the
following tracking points and polygon - q11.0, 1.0, 1.0
- q200.0, 0.0, 0.0
- p11.0, 0.0, 0.0
- p20.0, 2.0, 0.0
- P30.0, 0.0, 1.0
19Example
- Find a plane for the polygon.
- lengthsqrt(pow(1.0-0.0,2)pow(0.0-2.0,2)pow(0.
0-0.0,2))2.236 - v10(1.0-0.0)/2.2360.447
- v11(0.0-2.0)/2.236-0.894
- v12(0.0)/2.2360.0
- lengthsqrt(pow(0.0-0.0,2)pow(0.0-2.0,2)pow(1.
0-0.0,2))2.236 - v20(0.0-0.0)/2.2360.0
- v21(0.0-2.0)/2.236-0.894
- v22(1.0-0.0)/2.2360.447
- plane0 v11v22-v12v21-0.8940.447-
0.0-0.894-0.4 - plane1 v12v20-v10v220.00.0-0.477
0.477-0.228 - plane2 v10v21-v11v200.447-0.894
0.8940.0-0.4 - plane3 -(plane0p20plane1p21plane
2p22) - -(-0.40.0-0.2282.0-0.40.0)0.45
6 - // plane-0.4, -0.228, -0.4, 0.456
20Example
- Find the distance of each point to the plane
formed by your polygon. - dist1plane0q10plane1q11plane2q1
2plane3 - -0.41.0-0.2281.0-0.41.00.456
-0.572 - dist2plane0q20plane1q21plane2q2
2plane3 - -0.40.0-0.2280.0-0.40.00.456 0.456
- Points are on either side of the plane so there
might be a collision.
21Example
- Find the point where the line segment crosses the
plane. - lambda- 0.456 /(-0.572 - 0.456)0.444
- q0(q10-q20)lambdaq20
- (1.0-0.0)0.4440.00.444
- q1(q11-q21)lambdaq21
- (1.0-0.0)0.4440.00.444
- q2(q12-q22)lambdaq22
- (1.0-0.0)0.4440.00.444
- //q0.444, 0.444, 0.444
22Example
- Reduce to a 2D problem to keep it simple
- // plane-0.4, -0.228, -0.4, 0.456
- // use x and z coordinates and ignore y
- nx0 ny2
23Example
- Convert to a triangular coordinate system. Note
that much of this information can be
pre-computed. - x1p300.0 x2p200.0 x3p101.0
- y1p321.0 y2p220.0 y3p120.0
- xq0 0.444 yq20.444
- a1x2y3-x3y20 b1y2-y30 c1x3-x21
- a2x3y1-x1y31 b2y3-y1-1 c2x1-x3-1
- a3x1y2-x2y10 b3y1-y21 c3x2-x10
- deta1x1b1y1c11
- t1(a1b1xc1y)/det(0010.444)0.444
- t2(a2b2xc2y)/det(1-10.444-10.444)0.112
- t3(a3b3xc3y)/det(010.4440)0.444
- All values are between 0 and 1, so there is a
collision!
24How About After The First Collision?
- Hard to figure out when you are no longer in
collision with an object because the next time
you sample your points, q1 and q2 are likely to
both be inside the object. - How can we decide if we are still in collision?
- After collision, dont update q2.
- Redefine q2 using the normal using the last
polygon of collision. - If the polygons form a manifold that is convex,
then you make sure that your current position is
behind each plane
25Increase Efficiency with Spatial Partitioning
(Voxels)
- Create a cube (or voxel) that encloses your
polygons of interest. - Subdivide this cube into eight cubes (or
sub-voxels), then subdivide each of these new
cubes into eight new cubes. Keep subdividing till
desired resolution. - Sort your polygons so that for each cube you have
a list of polygons which each have at least 1
vertex in that cube. - For collision detection you now determine what
cube you are in and then you do standard polygon
collision detection on the polygons associated
with that box.
26Increase Efficiency with Spatial Partitioning
(Voxels)
27Potential Problems With Spatial Partitioning
- If you do not sample tracking at a high enough
rate, you may find that the appropriate collision
polygon is not in the voxel containing your
current position (q1) or the voxel containing
your previous position (q2).
28Potential Problems With Spatial Partitioning
You can always move back up your tree and test
at a lower resolution or test all the voxels
between your current position and your last
position.
29Potential Problems With Spatial Partitioning
- If the objects in your scene are moving you may
have to resort all of your polygons. - If your object deforms, than you may need to
resort all of your polygons.
30Constructive Solid Geometries (CSG)
- Build an object with simple solid primitives,
such as cubes, spheres, cones, etc. You just
need to test each primitive and then do polygon
collision for a primitive in collision. - Problem is that you may need allot of primitives
to represent complex geometries (such as objects
with filleting joints). - Can also use voxel trees to sort primatives
31Using Solid Models
- Test your current position with all of your
implicit models. - Can find intersection point using ray-surface
intersection test.
32Using Solid Models
- Can also test against rendering polygons
- Most likely, you have created a polygon
representation of your solid to render it. - If there is a collision, then do collision
detection on the polygons of that particular
solid (this means you need to track the history
of the points of interest, i.e. keep track of q1
and q2). - Problem is that your object may be built from
allot of polygons.
33Parametric Surfaces
- Bezier patches, NURBS, etc.
- Do not necessarily need to represent a closed
manifold. - Repetitive subdivision of the surface into
smaller and smaller polygons allows you to
quickly zero in on the collision location.
34Predictive Collision Detection
- Great for a multiprocessor system using threaded
collision detection. - Use direction and velocity to guess where the
next collision might. - Can zero in on likely collision objects before
you hit them. - Allows you to start complex collision detection
before you hit the object. This can allow you to
respond faster when the collision actually does
take place.
35Bounding Volumes
- Use simple bounding volumes, such as spheres, to
enclose your objects and then determine if there
is an overlap (distance less than the radius of
either sphere). - May use subdivision similar to spatial
partitioning discussed earlier. - Other bounding volume techniques include using
axis-aligned boxes, cone trees, sphere trees and
octrees (like what we discussed under spatial
partitioning ).
36Public Domain Collision Detection Packages
- I-COLLIDE collision detection system
http//www.cs.unc.edu/geom/I_COLLIDE/index.html - RAPID interface detection systemhttp//www.cs.un
c.edu/geom/OBB/OBBT.html - V-COLLIDE collision detection systemhttp//www.c
s.unc.edu/geom/V_COLLIDE/ - Distance computation between convex
polytopeshttp//web.comlab.ox.ac.uk/oucl/work/ste
phen.cameron/distances/index.html - Some others include V-Clip and SOLIDhowever,
they may not be public anymore.
37Project 2
- Create a program that will display four types of
models of your choice - Polygon-Based (everyone needs to be able to
render a list of polygons) - Implicit Solid Utilize typical Boolean
operations. Ill provide a dll for turning the
resulting implicit model into a polygon model. - Bezier Patch I will give you the dll, but you
must create the surface. - NURB Surface I will give you the dll, but you
must create the surface. - Create a 3D cursor that you can move in space
(say a sphere with keyboard control). Signal
when you have collided with an object. - Each of you is responsible for generating one
object and managing collision detection for that
object. Share using dll. - Project Due May 19th.