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 8852799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:29:27+00:00 2026-06-14T13:29:27+00:00

I am working in Javascript. I have an array with points in 3d space

  • 0

I am working in Javascript. I have an array with points in 3d space and i want the points to NOT to be very close to the other points in the array. I mean, I want the distance between points to be greater than x. Now what I am doing is having a double for loop comparing distances and moving
the points further away in Z-dimension like

while(there_are_objects_that_are_close){
    for(all_the_objects){
        for (all_the_objects){
            if (distance_between_them < 100){
                object[i].z += 150;      
            }
        }
     }
}

The problem is that I hate this algorithm, it looks really slow and I am looking for a better solution. If you have a solution that is also an “algorithm with a name” with literature background I would appreciate it more as this is part of our school project.

  • 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-06-14T13:29:28+00:00Added an answer on June 14, 2026 at 1:29 pm

    Comparing each point against each point is indeed the simplest, so your algorithm is a good start.

    The downside of this is that when the amount of points becomes huge, the algorithm will start to behave pretty bad since it would have to compare each point against all points while the majority of points are not close. In such cases, you would want to split the points in such a way that you only check points which could be close enough.

    For static points (those that don’t move) it’s trivial to make a tree such that you just have to walk a few parent nodes and check its children (children that are closer together are closer in distance). This is also known as a R-tree, other options also exist.

    This applies to 3D as well.

    Both images are from Wikipedia.

    Visually you can see it becomes a lot more simple, you just check the boxes that are within your radius and you end up doing a lot less work that way.

    For dynamic points (those that move) it might not be feasible to keep such a detailed R tree present. Hence, we’ll have to step down on the level of detail and look for something between your approach and the R tree, just making slightly bigger boxes for example is one approach.

    Other approach involve using quads (you divide a cube into 4 smaller cubes each time, only if it contains a point) and a grid (you create a lot of equal sized cubes). You can read more about R trees and the other structures here, it serves well as an introduction to them.

    A derivative of this is for instance the geodesic grid which splits up a globe into triangles, although this might not be applicable to 3D (unless you connect the triangles with a vertex in the middle of the globe).

    Image is from Wikipedia.

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

Sidebar

Related Questions

I'm working on a security project in Javascript (something I honestly have not used),
I'm working on a javascript game for fun, where I have an array of
In a JavaScript application that I am working on I have an array of
Working in jQuery or plain javascript If i have an array of objects like
I have a working JavaScript code below which dynamically creates JSON object using JSON.parse
So I have been working with javascript for a website I am designing, shocker
I have a javascript function, that works fine if it's anonymous but stops working
Hi Javascript gurus, I have this Javascript code which is working fine on Firefox
Working on an AJAX website (HTML,CSS,JavaScript, AJAX, PHP, MySQL). I have multiple javascript functions
I am working on a javascript project which involves parsing xml data. I have

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.