Collision Detection
Collision Detection
Collision Detection
Any shape which tends to change in motion is usually well bounded by a sphere. So
e.g. a human acrobat hitting a wall would be approximated by the collision of a sphere
with centre P, radius r, and a plane L.
Let point P have position vector p, and L have equation s.n=d, where n is normalised
(that is, n is a unit vector). Referring to chapter 12, the distance of point P from the
plane is also given by the dot product p.n−d.
So when p.n−d = r, we can say that the sphere is in contact with the plane.
The time of collision depends on the velocity (speed and direction) of the sphere, and
on the distance it must cover until its central point lies r from the plane. So let the
sphere start out centred at point P0 with position vector p0, and let it move with
velocity v (a vector).
1
Then the angle between v and n has cosine
v•n
v n
(be careful which way n is pointing). The distance along n is the distance from P0 to
the plane, with d reduced by r, that is p.n− (d−r).
Therefore the distance l to collision from the starting point in the direction of motion
p0 • n − d + r
l = v
v•n
If the time t to collision is negative, the collision has already taken place.
Example 1
What is the distance l and the time t to collision of a sphere of radius r = 6cm, starting
at point p0 = 5i +2j +4k, and moving with velocity v = i +3j +3k cm/s with the plane
r.n = d (20i +25j +30k).(0.7071i +0.5657j +0.4243k) = 3.5356?
2
v • n = (i + 3 j + 3k ) • (0.7071i + 0.5657 j + 0.4243k )
= 1 0.7071 + 3 0.5657 + 3 0.4243 = 3.6771
p • n − d + r = 8.8285
p • n − d + r 8.8285
= = 2.4009
v•n 3.6771
v = 12 + 32 + 32 = 19 = 4.3589
p •n−d +r
l = v 0 = 4.3589 2.4009 = 10.4653
v•n
Exercise 1
What is the distance l and the time t to collision of a sphere of radius r = 5cm, starting
at point p0 = 5i +10j +15k, and moving with velocity v = 10i +20j +30k cm/s with the
plane r.n = d (100i +125j +150k).(0.4767i +0.5721j +0.6674k) = 219.2925?
Imagine a sphere moving around a space of several irregular objects. These objects
could be any shape, and have any number of faces, edges and surfaces. Collision with
a face is collision with a plane, as above. Generally speaking, collision occurs when
the centre of the sphere lies one radius away from the plane along the normal to that
plane.
Collision of the sphere with an edge occurs when the centre of the sphere lies on the
surface of a cylinder of radius r having the edge as centre.
3
Collision of the sphere with a corner occurs when the centre of the sphere lies on the
surface of sphere of equal radius r having the corner as centre.
All of these factors can be taken into account by surrounding the object with a
bounding volume tailored to lie one radius from the actual surface.
4
Let a point PS with vector aSi+bSj+cSk lie on the surface of this expanded object. Then
collision occurs when the distance between PS and the point P0 (at the centre of the
sphere) with vector a0i+b0j+c0k is zero. Recalling the distance between two points to
be the magnitude of the difference between their position vectors, collision occurs
when
a s i + bs j + cs k − (a0i + b0 j + c0 k )
.
With two moving objects, the calculations are a bit more complicated. Consider two
spheres, S1 with centre P and radius r1, and S2 with centre Q and radius r2.
Let sphere S1 start out at point P0 at time t=0 and head towards point P1, which it
reaches at time t=1. Then S1 has velocity
P − P0
V1 = 1 = P1 − P0
1 .
The position of the centre P of S1 between these two times will depend on P0 and V1,
P(t ) = P0 + tV1
.
Let sphere S2 start out at point Q0 at time t=0 and head towards point Q1, which it
reaches at time t=1. Then S2 has velocity
Q − Q0
V2 = 1 = Q1 − Q0
1 .
The position of the centre Q of S2 between these two times will depend on Q0 and V2,
Q(t ) = Q0 + tV2 .
The collision takes place when the distance l between the two spheres is exactly the
sum of their radii. If we square everything, we avoid difficulties caused due to the
5
distance l widening (after collision) rather than closing (before the collision).
l 2 = P (t ) − Q (t )
2
l 2 = P0 + tV1 − Q0 − tV2
2
l 2 = (P0 − Q0 ) + t (V1 − V2 )
2
Which is a quadratic equation in t. We can use the quadratic formula to solve for t;
− 2(P0 − Q0 ) • (V1 − V2 ) 2(P0 − Q0 ) • (V1 − V2 )2 − 4(V1 − V2 ) • (V1 − V2 )(P0 − Q0 ) • (P0 − Q0 ) − l 2
t=
2(V1 − V2 ) • (V1 − V2 )
which simplifies to
− (P0 − Q0 ) • (V1 − V2 ) (P0 − Q0 ) • (V1 − V2 )2 − (V1 − V2 ) • (V1 − V2 )(P0 − Q0 ) • (P0 − Q0 ) − l 2
t=
(V1 − V2 ) • (V1 − V2 )
because we need only the negative root- the positive refers to the same distance after
collision. If the time to collision is negative, it's already happened.
The collision speed CS of the spheres is the magnitude of the combined velocity of the
spheres,
CS = V1 − V2
,
If the time to collision is negative, this will be the distance from the collision.
Example 2
Find the time t and distance x to collision of two spheres S1 and S2, both of radius
r = 5cm, if S1 starts at P0 = 100i +100j +100k at time t = 0 and has velocity V1 = −2i
−2j −2k cm/s, while S2 starts at Q0 = 3i +3j +3k at time t = 0 and has velocity V2 = 2i
+2j +2k cm/s.
6
V1 − V2 = −2i − 2 j − 2k − (2i + 2 j + 2k )
= −4i − 4 j − 4k
(V1 − V2 ) • (V1 − V2 ) = (− 4i − 4 j − 4k ) • (− 4i − 4 j − 4k )
= 3 (− 4) (− 4)
= 48
l 2 = (5 + 5) = 100
2
− (− 1164) + 4800
=
48
1164 + 69.2820
=
48
1233.2820
=
48
= 25.69
Collision speed is
CS = V1 − V2 = − 4i − 4 j − 4k = 42 + 42 + 42 = 48 = 6.9282
7
177.99cm.
Exercise 2
Find the time t and distance x to collision of two spheres S1 and S2, of radii r1 = 10km
and r2 = 8 km, if S1 starts at P0 = 3i +3j +3k at time t = 0 and has velocity V1 = 5i +5j
+5k km/s, while S2 starts at Q0 = 300i +300j +300k at time t = 0 and has velocity V2 =
−5i −5j −5k km/s.
(Just for your reference- this won't be covered in class nor is it examinable.) Vehicles
are usually well bounded by some type of box. A box has three dimensions, directions
at right angles to each other from side to opposite side. These dimensions are given
vectors R, S, T which describe both their length and direction.
Depending on the orientation of the box to the plane, the centre of the box (where the
dimension vectors cross) may be at a different effective radius reff (perpendicular
distance from whatever the box is touching).
Given a plane with normal direction n, he formula for the effective radius is
reff = ( R • n + S • n + T • n )
1
2 .
8
Let the box start out centred at point P0 with position vector p0, and let it move with
velocity v.
By similar arguments to those for the sphere, the distance l to collision from the
starting point in the direction of motion
p0 • n − d + reff
l = v
v•n
9
Tutorial
1. What is the distance l and the time t to collision of a sphere of radius r = 12cm,
starting at point p0 = 4i +8j +12k, and moving with velocity
v = 20i +20j +30k cm/s with the plane
r.n = d (80i +85j +90k).(0.3714i +0.5571j +0.7428k) = 143.9175?
2. What is the distance l and the time t to collision of a sphere of radius r = 7cm,
starting at point p0 = 100i +120j +130k, and moving with velocity
v = −10i −10j −5k cm/s with the plane
r.n = d (2i +2j +3k).(−0.1048i −0.3145j −0.9435k) = −3.6691?
3. Find the time t and distance x to collision of two spheres S1 and S2, of radii r1 = 4m
and r2 = 6m, if S1 starts at P0 = 4i +4j +4k at time t = 0 and has velocity V1 = 10i +10j
+10k m/s, while S2 starts at Q0 = 500i +500j +500k at time t = 0 and has velocity V2 =
−5i −5j −5k m/s.
4. Find the time t and distance x to collision of two spheres S1 and S2, of radii r1 =
12cm and r2 = 8cm, if S1 starts at P0 = −60i −60j −60k at time t = 0 and has velocity
V1 = 4i +4j +4k cm/s, while S2 starts at Q0 = 400i +400j +400k at time t = 0 and has
velocity V2 = −8i −8j −8k cm/s.
10