Implementation of a Naive Collision Detection Algorithm

The algorithm I have implemented in the demo below works like this:

given a list of polygons which are moving in the plane-

1. at each time step{

2.     for each polygon_p in polygons{

3.         for each polygon_q in polygons{

4.             if( polygon_p != polygon_q ){

5.                 for each edge_e in polygon_p_edges{

6.                     for each edge_f in polygon_q_edges{

7.                         if( edge_e->Intersects( edge_f ){

8.                             return polygon_p intersects polygon_q
                           }}}}}}}
 

This algorithm could be sped up by using a bounding box around all of the polygons,
changing line 4 to:

4.             if( polygon_p != polygon_q and
                     polygon_p_bounding_box->Intersects( polygon_q_bounding_box ) ){
 

cd_demo.exe requires win9x and Direct Draw 5.0 or greater.  Run the program to see the
algorithm at work, press [ESC] to quit.

The source code available here is all of the (mostly) platform independent code.  The Windows
and Direct Draw code is not included.

The following files can be downloaded.

cd_demo.exe
world.h
world.cpp
asteroid.h
asteroid.cpp
edge.h
edge.cpp
vertex.h
vertex.cpp