Say there are n 3-dimensional objects (polyhedra). Is the fastest way to calculate the intersection of all objects O(n ^ 2)?
Right now, I'm using a library that essentially forces T(n) to equal n ^ 2:
for each object: // there are n objects
get list of intersecting objects // this takes n steps
That literally takes n ^ 2 steps.
The only faster way that I can think of is still O(n ^ 2), but T(n) = n(n+1) / 2, or (n*n + n) / 2.
Here's pseudocode:
for(int i = 0; i < len(objects) - 1; i++)
for(int j = i + 1; j < len(objects); j++)
if object at i intersects object at j:
object at i . addToIntersectList ( object at j )
object at j . addToIntersectList ( object at i )
This way we don't have to check to see if two objects intersect twice. I know there are about 3000 objects in the list I am iterating through. This algorithm takes 4501500 steps, whereas the original algorithm takes nearly double that, 9000000 steps.
Am I missing something? Is this the best we can get?