0
\$\begingroup\$

For the most simple of 2D games, I have implemented a posteriori collision detection (overlapping rectangles) on the xy Cartesian plane, but am now interested in understanding the basics of a priori collision detection...

On Wikipedia's entry on collision detection, I noticed the reference to Newton’s Method. So, I want to better understand the link between finding zeros of an equation and detecting a posteriori collision.

Let's start with the most obvious case of finding roots of an equation: If you have a projectile's trajectory modeled as a quadratic function, you can find the roots to predict at what time the height will equal zero (or any other constant height, actually, by just rearranging f(x)=C to be f(x)-C=0 and then finding roots of that expression).

So, as I understand, finding the root can tell me the time at which the object will be at any chosen height. More broadly, we basically know the (x,y) location of the object for any given time.

But how does root finding, in particular, translate to detecting collisions with another object? The other object may be stationary, or be moving. If the latter, do you also determine roots/location of this moving object as well? Calculate the (x,y) trajectory of both objects and determine where they will intersect?

\$\endgroup\$
2
  • \$\begingroup\$ You had the start of a good question, but you concluded it by asking for links to tutorials. This site is not meant to provide those. \$\endgroup\$ Commented Dec 7, 2013 at 21:10
  • 1
    \$\begingroup\$ Ok, then ignore that last part? \$\endgroup\$ Commented Dec 7, 2013 at 21:23

1 Answer 1

0
\$\begingroup\$

Very simply, if you define the minimum distance between two moving bounding volumes as a function of time, D(t), then the roots (a.k.a. zeros) of that function are obviously the set of times, {t1, t2, ... tn}, when the distance between the volumes is exactly zero, D(t1)=0, D(t2)=0, ... D(tn)=0. If the volumes collide at some time in past or future, then one or more of those roots will be real. The smallest real root that is greater than or equal to the current time can usually be described as the time of the initial collision between the two volumes. If the volumes never collide in the past or future, then D(t) will have no real roots, because it is never equal to zero anywhere at any time, in which case it will only have imaginary roots. So, simply by examining the presence or lack of real roots in the distance function, you can determine if a collision occurs or not.

Polynomial functions up to degree 3 (i.e. "cubic"; ax3+bx2+cx+d) have well-defined roots that can be derived algebraically very easily. Polynomials of degree 4 (a.k.a. quartic) also have a relatively straight forward solution for their roots which was provided by Lodovico Ferrari, so it is sometimes called Ferrari's Method. For functions that are more complex than that, you can use Newton's method to systematically find roots between some tmin and tmax. Newton's method actually is somewhat ideal for collision detection, since we are usually only concerned with finding collisions between some known time interval. There's almost never any need to hunt down all of the roots for this application. Furthermore, the precision that we require for collision events often isn't very high. The precision of the root being computed can be tuned in Newton's method by simply increasing or decreasing the number of iterations spent in its loop.

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.