CS121 Project 2

Messy details: errors, rolling, and stopping



Numerical inaccuracies are inevitable. For example, the point on a line (e.g. ball's path) that is r units from a plane (e.g. triangle) may have real coordinates that require infinite precision to represent. Representing the point with finite precision introduces round-off error. You must anticipate and accomodate these round-off errors.

In particular, if you reset the ball's position to the point of collision as reported by the collision detection algorithm, the ball may actually be intersecting the triangle. This isn't a problem if the ball moves out of the triangle during the current time step. But if there isn't much time left in the time step and/or if the ball is moving roughly parallel to the plane, the ball may be intersecting the triangle at the end of the time step. When gravity is applied in the next time step the ball may move deeper in the plane containing the triangle but no collision is be detected. To avoid this problem you can (should)
  1. Detect collisions when the ball is r-ε away from the plane; i.e. when it is intersecting by some small amount
  2. Move the ball's position ε away from the surface when a collision is detected; i.e. if p is the position when the collision is reported to occur, reposition the ball at pn, where n is the surface normal (possibly a composite normal if multiple collisions occur).
Note: use the same ε in both cases since otherwise you may move the ball so it intersects some other triangle in a non-detectable way!

Rolling raises a variety of problems that have a variety of solutions. In the abstract, when the ball is rolling it is constant contact with a triangle. Collisions are constantly reported, reflecting the velocity vector does not change it, and the ball never moves. In practice, this doesn't happen, because of numerical inaccuracies. In fact, if you use the detect/correct algorithm described above for errors in the collision point, rolling is vastly simplified. When a collision is detected you move the ball away from the surface so it is not colliding. The ball then can move, roughly parallel to the surface, until another collision occurs. Repeated collisions are inevitably since gravity is added at the start of each time step. You can also detect rolling and only add the component of gravity parallel to the surface but this enhancement is not really necessary. Note that ε (from the detect/correct algorithm) is small so the movement of the ball away from the surface is unnoticably when the velocity parallel to the surface is relatively large. Two remaining issues with rolling are damping and stopping.