CS121 Project 2

Vertex Collision Notes




A collision between a ball and a triangle can occur on the triangle's face, edge, or vertex (Fig. 1). These notes describe an algorithm for detecting vertex collisions. Separate notes describe face and edge collisions.

Let v = (x, y, z) be the vertex under consideration. Let the starting and ending positions of the ball be p0 = (x0, y0, z0) and p1 = (x1, y1, z1).

We first determine if there are points on the line L containing the ball's path that are exactly r units from v. We then analyze the points to determine if they constitute a vertex collision.

We can represent L parametrically as p0 + β (p1 -p0). Each point on L corresponds to a unique value of β. In particular, p0 and p1 correspond to β=0 and β=1, respectively. Points on the line segment between p0 and p0 correspond to values of β in the range (0,1).

For any fixed value of β, the point p =p0 + β (p1 -p0) is a distance r from v if and only if

[x0 + β(x1 -x0) - x ]2 + [y0 + β(y1 -y0) - y ]2 + [z0 + β(z1- z0) - z ]2 - r2 = 0.
We can rewrite this expression as a quadratic in β. This quadratic has 0, 1, or 2 real roots. We analyze each of the cases.
  1. If the quadratic has no real roots then no point on L is r units from v. In this case we simply report that no vertex collision occurs; i.e. we return α=1.
  2. If the quadratic has one real root, β=s, then exactly one point on L, namely p0 + s (p1 -p0), is a distance r from v. This also means that no point on the line is closer than r from v. Thus a vertex collision can only occur when the ball's center is at p0 + s (p1 -p0). This point is on the ball's path if 0 ≤ s ≤ 1. If this test passes, we need to determine if the collision occurs on the front of the incident triangle. We check if the dot product of the front-facing triangle normal and the vector from p0 to p1 is less than or equal to zero. If so, return α=s; if not we return α=1. In the former case we also return the triangle normal.
  3. Finally we consider the case where the quadratic has two real root, s0 and s1. We'll assume that s0 < s1. We claim that the only root of interest is s0 and the test for collision is the same as for s in the previous case.
    Proof of claim: The roots s0 and s1 correspond to points S0 and S0 that define the region of L that is a distance r or less from v. We consider three cases that depend on the relationship of p0 to S0 and S1.
    1. If p0 occurs before S0 (as β increases from negative infinity), then v is less than r from p0; this means the vertex is initially inside the ball. the first point on the ball's path that is r units from the v is S0. So it suffice to check that point.
    2. If p0 occurs after S0 but before S1 then the vertex is inside the ball at its starting position. But this can't happen.
    3. If p0 occurs after S1, then no vertex collision occurs. In this case s0 < s0 < 0 and our test reports that no collision occurs.