intersection detection
intersection detection
Intersection Detection
References
Notes based on
Tomas Moller and Eric Haines, Real-Time Rendering, A K Peters,
2nd edition, 2002. Chapter 9.
Franco Preparata and Michael Shamos, Computational Geometry:
An Introduction, Springer Verlag, 1990. Chapter 2.
Intersection Detection
Introduction
Intersection Detection
Three Possibilities
Intersection Detection
Bounding Volumes
Intersection Detection
Types of Bounding Volumes
Common bounding volumes (BVs) are:
1. Axis-aligned bounding boxes (AABBs).
2. Oriented bounding boxes (OBBs).
3. Discrete oriented polytopes (k-DOPs).
4. Spheres.
There is an obvious trade-off: tightness of fit versus complexity
and cost of test.
Intersection Detection
Axis-Aligned Bounding Boxes (AABBs)
Intersection Detection
Oriented Bounding Boxes (OBBs)
An oriented bounding box is a box which may be arbitrarily
oriented (rotated). It is still a box; its faces have normals which
are pairwise orthogonal.
Intersection Detection
Discrete Oriented Polytopes (k-DOPs)
A k-DOP is the intersection of a set of pairs of parallel planes,
where each pair of parallel planes is called a slab.
Intersection Detection
Intersection Detection Principles or “Rules of Thumb”
Intersection Detection
Point-Point Intersection Testing
Intersection Detection
Interval-Interval Intersection Testing
Two intervals [amin , amax ] and [b min , b max ] are disjoint (do not
intersect) if either amin > b max or b min > amax .
interval intersect(A, B)
returns (OVERLAP,DISJOINT)
1: if (amin > b max or b min > amax )
2: return (DISJOINT);
3 else
4: return (OVERLAP);
Intersection Detection
AABB-AABB Intersection Testing
AABB intersect(A, B)
returns (OVERLAP,DISJOINT)
1: for each i ∈ x, y , z
2: if (aimin > bimax or bimin > aimax )
3: return (DISJOINT);
5: else
4: return (OVERLAP);
Intersection Detection
Sphere-Sphere Intersection Testing
Two spheres intersect if the distance between their centres c1 and
c2 is less than the sum of their radii r1 + r2 .
sphere intersect(A, B)
returns (OVERLAP,DISJOINT)
1: l = c2 − c1
2: d 2 = l.l
3: if (d 2 < (r1 + r2 )2 )
4: return (OVERLAP);
5: else
6: return (DISJOINT);
d
o
Intersection Detection
Representing Rays
r = o + td
x = xo + tu
y = yo + tv
z = zo + tw
Intersection Detection
A ray may also be specified by giving two points p1 and p2 in
which case the equations become:
x = x1 + t(x2 − x1 )
y = y1 + t(y2 − y1 )
z = z1 + t(z2 − z1 )
Intersection Detection
Ray-Sphere Intersection Testing
A sphere may be represented by the equation
(u 2 + v 2 + w 2 )t 2 +
2(u(xo − a) + v (yo − b) + w (zo − c))t +
(xo − a)2 + (yo − b)2 + (zo − c)2 − r 2 = 0
i.e. a quadratic in t. If the quadratic has real roots then the ray
intersects the sphere, otherwise it does not.
Intersection Detection
So we have
A = (u 2 + v 2 + w 2 )t 2
B = 2(u(x0 − a) + v (y0 − b) + w (z0 − c))t
C = (x0 − a)2 + (y0 − b)2 + (z0 − c)2 − r 2
t2
t 1= t 2
t1
d d
d
o o o
Intersection Detection
Minor Optimisation
and √
−B ± B 2 − AC
t=
A
These kinds of optimisations tend to be of decreasing value with
increasing floating point performance. They are also potential
source for introducting bugs and creating obscurity.
Intersection Detection
Optimised Solution
Haines optimised version of the ray-sphere intersection detection
algorithm allows earlier short-circuiting.
ray sphere intersect(o,d,c,r)
returns (REJECT,INTERSECT,t,p)
1: l=c - o
2: d = l.d
3: l 2 = l.l
4: if (d < 0 and l 2 > r 2 ) return (REJECT,0,O);
5: m2 = l 2 − d 2
2 2
6: if (m√ > r ) return (REJECT,0,O);
7: q = r − m2 2
8: if (l 2 > r 2 ) t = d − q else t = d + q
9: return (INTERSECT,t,o + td);
Intersection Detection
Ray-Polygon Intersection Detection
To find the intersection point between a ray and a polygon:
1. Find the intersection point of the ray and the plane containing
the polygon. If it does not exist then finished.
2. Determine if the ray-plane intersection point is inside the
polgon, i.e., perform a point-polygon intersection
(containment) test.
Intersection Detection
Ray-Polygon Intersection Point
The equation of a plane is
Ax + By + Cz + D = 0
x = xo + tu
y = yo + tv
z = zo + tw
Rearrangement gives
(Axo + Byo + Czo + D)
t=−
Au + Bv + Cw
Intersection Detection
Polygon Containment Test
The polygon containment test is performed by projecting the
polygon and the intersection point onto one of the coordinate
planes along one of the three principal axis directions and then
performing a 2D point in polygon test.
Which axis do we project along?
Intersection Detection
Point in Polygon: Crossings Test
One O(n) approach is to count the number of crossings or
intersections between a semi-infinite line or ray and edges of the
polygon.
P
p3
p4 C
p2
p5
p1
The point q can be any internal point, e.g., the centroid of the
triangle determined by any three vertices of P.
Using polar coordinates, a binary search can be performed to find
the wedge which contains z. Then z can be compared against the
wedge edge.
How much preprocessing is required?
Intersection Detection
Concave Polygons
Intersection Detection
Brute Force Collision Detection
A brute force approach to collision detection uses intersection tests
of all object pairs — or pairwise testing — at discrete points in
time where all objects are assumed to be stationary
1: for i = 1 to n − 1
2: for j = i to n
3: intersect(object(i), object(j))