Say there are n three-dimensional objects (polyhedra). The fastest way to calculate the intersection of all objects O (n ^ 2)?
I am now using a library that essentially makes T (n) equal n ^ 2:
for each object:
get list of intersecting objects
It literally takes n ^ 2 steps.
The only faster way I can think of is still O (n ^ 2), but T (n) = n (n + 1) / 2 or (n * n + n) / 2.
Here's the pseudo code:
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 )
Thus, we do not need to check if two objects intersect twice. I know that in the list that I iterate over there are about 3,000 objects. This algorithm takes 4,501,500 steps, while the original algorithm takes almost twice as many as 9,000,000 steps.
Am I missing something? Is this the best we can get?