Suppose I had a an array of cubes with dimensions D * D * D.
For example, here is an image of an array of cubes where D = 3: a 3x3 array of cubes
I will refer to the array, being the collection of all cubes, and a cube being one single cube that is part of the array.
Each cube is of uniform size (S), and they are arranged in such a way where their sides touch each other, and there is no overlap. Just like the image. Each cube's center can be described as C.
Now imagine ranking these cubes in descending order of distance from point P to the cube's center C. The furthest cube from point P (max distance between P and C) will be given rank 1; the closest cube from point P will be given the largest number rank.
Given the following are true:
- Each cube is aware of its position in the array
- the rotation/orientation of the array is known
- each cube can be identified in any logical way. I would assume it's x, y and z positions in the array would make sense for identifying an individual cube
Given you following are known:
- P: the point we are measuring distance from
- M: the mid point of the cube array
- S: the size (side length) of each cube
- R: the Euler rotation (x, y, z) of the array.
I am looking for a function that will find me the cube ranked N by distance from point P to the cubes center C.
Constraint:
- I cannot assess the distance of all cubes to find which cube is ranked N. Although, it may be acceptable to assess the distance of one or two other cubes if it helps somehow.
I am a programmer, so I am actually looking for an algorithm or formula that will be performed on the GPU, in parallel, for each rank N at the same time.
Does such a function exist? Does this problem have a solution?
Thank you.
Edit:
For clarity, I am not intending to define areas in which the cubes fit. I am simply trying to rank the cubes based on their center position.
The most important thing is for each cube to given its own rank. I would accept solutions that have 2 cubes in slightly wrong order if they have, for example, very similar distances from P, but not a solution that can result in multiple cubes being given the same rank.