Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7546071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:06:14+00:00 2026-05-30T09:06:14+00:00

I have unknown number of objects in 3D Space, I would like to know

  • 0

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;
           }
       }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T09:06:16+00:00Added an answer on May 30, 2026 at 9:06 am

    I can think of three solutions, each with a different time\space tradeoff.

    n x n array

    If you have a small number n of objects and a distance function D(n1, n2), you can compute the distances in advance.

    Create a 2D n X n array. In array[i, j] store the result of D(ni, nj).

    Pros:

    • After the initial calculation, the answer for any two objects is given in O(1).
    • Simplicity

    Cons:

    • inefficiency for large data sets
    • Can’t easily add new objects on-the-fly

    Memoization

    Memoize your distance function to remember previous calls.

    R-Tree

    The standard data structure for storing objects in 2D\3D Objects like Points and Polyhedrons is R-Trees. In short, your objects are grouped into 3D cubes of near-by items. It provides efficient insertion and lookup time of log(n) time, and threshold distance lookup is extremely efficient, especially when the answer is negative.

    Quoting the Wikipedia article:

    A common real-world usage for an R-tree might be to store … polygons that typical maps
    are made of: streets, buildings, outlines of lakes, coastlines, etc.
    and then find answers quickly to queries such as “Find all museums
    within 2 km of my current location”, “retrieve all road segments
    within 2 km of my location”

    And:

    The key idea of the data structure is to group nearby objects and
    represent them with their minimum bounding rectangle in the next
    higher level of the tree; the “R” in R-tree is for rectangle.

    You have R-Tree implementations in most modern programming languages.

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Thanks for taking the time to read this. I have an unknown number of
I have a graph which contains an unknown number of disconnected subgraphs. What's a
I have an application that reuses an Activity an unknown number of times. It
I have a repeater control, and I want to put an unknown number of
I have numerous functions (unknown at design time) that each take a specific number
I have an array of points in unknown dimensional space, such as: data=numpy.array( [[
I want to be able to create and unknown number of objects. I'm not
I have two arrays: var columns = ["Date", "Number", "Size", "Location", "Age"]; var rows
Is there a way to concatenate a unknown number of querysets into a list?
I have an array of unknown (to the current method) class objects. I do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.