I have unknown number of objects in 3D Space, I would like to know what is the fastest way to detect if two objects or many objects have a distance less than a threshold between each others. I think that is an n! problem, but I would like a better way for solving it.
I have tried the following pseudo code, and I need your comment about it.
for (int y=0; y<blobList.size();y++){
for (int x =1; x<blobList.size();x++)
{
CvPoint *blob_a = new CvPoint();
CvPoint *blob_b = new CvPoint();
blob_a->x = blobList[x].second->maxx;
blob_a->y = blobList[x].second->maxy;
blob_b->x = blobList[y].second->maxx;
blob_b->y = blobList[y].second->maxy;
double dist = distance(blob_a,blob_b);
cout<< " distance between blob "<<blobList[y].second->label<<"and "<<blobList[x].second->label<<endl;
cout<<dist<<endl;
if( dist<ParamMgr.fDistance)
{
cout<< " Collision between "<<blobList[y].second->label<<"and "<<blobList[x].second->label<<endl;
}
else {
cout<< " "<<endl;
}
}