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.

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.