I have a row that can contain up to N
points. I want to distribute x
points inside that row from the center outwards, using as little space.
I have managed to distribute points evenly within the row, but it uses all of the available space. Using the formula floor((i+0.5)*N/x)
, I get the following result, considering N=9
:
4
2 6
1 4 7
1 3 5 7
0 2 4 6 8
0 2 3 5 6 8
0 1 3 4 5 7 8
0 1 2 3 5 6 7 8
0 1 2 3 4 5 6 7 8
The following is an example graphical representation of the indeces shown in the output above:
I want to basically restrict points from going too far outwards from the center, so I get a result more like:
4
3 5
3 4 5
2 3 5 6
2 3 4 5 6
1 2 3 5 6 7
1 2 3 4 5 6 7
0 1 2 3 5 6 7 8
0 1 2 3 4 5 6 7 8
The following is an example graphical representation of the indeces shown in the output above:
I'm using Java and this is my current code
int rowLength = 9;
for (int points = 0; points <= rowLength; points++) {
for (float i = 0; i < points; i++) {
double result = Math.floor((i + 0.5) * rowLength / points);
System.out.print((int) result + " ");
}
System.out.println();
}
How can I best achieve the result shown in the second image so that the output from my code matches that of the second example output?