1

For example, in a 2D space, with x [0 ; 1] and y [0 ; 1]. For p = 4, intuitively, I will place each point at each corner of the square.

But what can be the general algorithm?

barbacan
  • 632
  • 6
  • 16
  • You didn't seem to provide an algorithm for 2D. – gsamaras Nov 30 '17 at 08:18
  • Indeed, hence my question... – barbacan Nov 30 '17 at 08:38
  • 2
    You didn't define the function you want to optimize. What if I have two solutions, whose average distance between points are the same but in one of the solution the minimal distance between two specific points is very small ? – fjardon Nov 30 '17 at 08:39
  • Following up on @fjardon, do you want to maximize the sum of pairwise distances or maximize the minimum distance between all pairs of points? Or something completely different? – SaiBot Nov 30 '17 at 09:23
  • I heard in my question that if you take two points at random, the distance will always be the same as much as possible. And I want to maximize this distance. – barbacan Nov 30 '17 at 10:24
  • @barbacan you still don't define what you're trying to maximize. Voted to close. – fjardon Nov 30 '17 at 10:30
  • I have p points, I want to space them as much as possible in a confined space. Is it so incomprehensible? – barbacan Nov 30 '17 at 11:05
  • 1
    It is hard to comprehend since "space them as much as possible" is ambiguous. Please define what exactly you mean. Look at my comment above and choose one of the options or define "space them out" more clearly. In the end we will need to settle on a function to maximize otherwise we cannot help. – SaiBot Nov 30 '17 at 11:28
  • "maximize the sum of pairwise distances" and "maximize the minimum distance between all pairs of points" is not equivalent ? – barbacan Nov 30 '17 at 11:40
  • No, to be more formal a) [maximize this](http://latex.codecogs.com/gif.latex?%5Csum_%7Bp_i%20%5Cin%20P%7D%20%5Csum_%7Bp_j%20%5Cin%20P%7D%20dist%28p_i%2C%20p_j%29) or b) [maximize this](http://latex.codecogs.com/gif.latex?min_%7Bp_i%20%5Cin%20P%2C%20p_j%20%5Cin%20P%5Csetminus%20p_i%7D%20dist%28p_i%2C%20p_j%29) where P is the set of points and dist() is euclidean distance. – SaiBot Nov 30 '17 at 12:09

2 Answers2

0

Edit: The algorithm needs modification if dimensions are not orthogonal to eachother

To uniformly place the points as described in your example you could do something like this:

var combinedSize = 0

for each dimension d in d0..dn {
    combinedSize  += d.length;
}

val listOfDistancesBetweenPointsAlongEachDimension = new List

for each d dimension d0..dn {
    val percentageOfWholeDimensionSize = d.length/combinedSize
    val pointsToPlaceAlongThisDimension = percentageOfWholeDimensionSize * numberOfPoints
    listOfDistancesBetweenPointsAlongEachDimension[d.index] = d.length/(pointsToPlaceAlongThisDimension - 1)
}   

Run on your example it gives:

combinedSize = 2

percentageOfWholeDimensionSize = 1 / 2

pointsToPlaceAlongThisDimension = 0.5 * 4

listOfDistancesBetweenPointsAlongEachDimension[0] = 1 / (2 - 1) listOfDistancesBetweenPointsAlongEachDimension[1] = 1 / (2 - 1)

note: The minus 1 deals with the inclusive interval, allowing points at both endpoints of the dimension

Adam
  • 2,845
  • 2
  • 32
  • 46
0
  1. 2D case

    In 2D (n=2) the solution is to place your p points evenly on some circle. If you want also to define the distance d between points then the circle should have radius around:

    2*Pi*r = ~p*d
    r = ~(p*d)/(2*Pi)
    

    To be more precise you should use circumference of regular p-point polygon instead of circle circumference (I am too lazy to do that). Or you can compute the distance of produced points and scale up/down as needed instead.

    So each point p(i) can be defined as:

    p(i).x = r*cos((i*2.0*Pi)/p)
    p(i).y = r*sin((i*2.0*Pi)/p)
    
  2. 3D case

    Just use sphere instead of circle.

  3. ND case

    Use ND hypersphere instead of circle.

So your question boils down to place p "equidistant" points to a n-D hypersphere (either surface or volume). As you can see 2D case is simple, but in 3D this starts to be a problem. See:

As you can see there are quite a few approaches to do this (there are much more of them even using Fibonacci sequence generated spiral) which are more or less hard to grasp or implement.

However If you want to generalize this into ND space you need to chose general approach. I would try to do something like this:

  1. Place p uniformly distributed place inside bounding hypersphere

    each point should have position,velocity and acceleration vectors. You can also place the points randomly (just ensure none are at the same position)...

  2. For each p compute acceleration

    each p should retract any other point (opposite of gravity).

  3. update position

    just do a Newton D'Alembert physics simulation in ND. Do not forget to include some dampening of speed so the simulation will stop in time. Bound the position and speed to the sphere so points will not cross it's border nor they would reflect the speed inwards.

  4. loop #2 until max speed of any p crosses some threshold

This will more or less accurately place p points on the circumference of ND hypersphere. So you got minimal distance d between them. If you got some special dependency between n and p then there might be better configurations then this but for arbitrary numbers I think this approach should be safe enough.

Now by modifying #2 rules you can achieve 2 different outcomes. One filling hypersphere surface (by placing massive negative mass into center of surface) and second filling its volume. For these two options also the radius will be different. For one you need to use surface and for the other volume...

Here example of similar simulation used to solve a geometry problem:

Here preview of 3D surface case:

simulation

The number on top is the max abs speed of particles used to determine the simulations stopped and the white-ish lines are speed vectors. You need to carefully select the acceleration and dampening coefficients so the simulation is fast ...

Spektre
  • 49,595
  • 11
  • 110
  • 380
  • Depending on the criteria that needs to be maximized, this might not be correct. Lets say you want to have maximum distance between each pair of points. You got 100 points in 2D and align them on a circle as you proposed. You can increase the distance if you take one of the points and place it in the middle of the circle, right? – SaiBot Nov 30 '17 at 11:59
  • @SaiBot yeas that is the last part I was still writing about. You can place some massive negative mass into the center of hyper-sphere or not... – Spektre Nov 30 '17 at 12:00
  • Well done, do you have to stick to the sphere or can it be a rectangle too? – SaiBot Nov 30 '17 at 12:38
  • @SaiBot it does not matter which shape you use but hypersphere has the min surface for the same volume in comparison to any other shape which suggest it should be used preferably than others... – Spektre Nov 30 '17 at 13:55
  • yeah I was just thinking about the simple example given in the question. 2D square space and 4 points. The results should be as mentioned each point in a corner. – SaiBot Nov 30 '17 at 14:22
  • @SaiBot hmm but then try 7 points .... and soon you realize that square is not enough – Spektre Nov 30 '17 at 15:39