Spread X amount of points among Y amount of points

61 Views Asked by At

Problem:

Say i have X amount of points with a arbitrary radius R in a box. Then there is a line formed by Y amount of identical points stacked right beside each other. So for example 2 points would have the length 2R on the line. Now i want to take the points i have in my box and spread them among the points on the line with maximal distance D between each other but D can never get smaller then R.

Restraints and exceptions:

  • Y > X
  • D $\geq$ R
  • It is ok if two points or more from the box are put right next to each other if they are forced to depending on the values of the variables.

Question:

What is the general formulas or algorithms that gives me distance D between the points and number of points that need to be stacked next to each other if the values of X and Y force it?

1

There are 1 best solutions below

0
On

Announcement:

Ok, nevermind this i found a solution that works pretty well. If anybody cares the solution is below with a sample program in c/c++.

Solution:

So for $X$ and $Y$ i make a variable called $r$ and set it to $\frac{Y}{X}$ and a counter variable called $J$ to keep track of where i am in the line (think of the line as a 1 dimensional array). Then i start going through the line and when $r$ rounded times $J$ rounded off is equal to or is greater than the current element in the array then place a point there and add one to $J$.

Code: https://pastebin.com/HbZjnpex