Reputation: 459
Let me clarify my question with a question:
Assume that I have a big cube = 100*100*100 and there are little cubes inside the big cube which construct big cube and their sizes are = 10*10*10. (I have 1000 little cubes inside the big cube) Now, I need to check, in which cube my point (2,2,2) exists. Answer is for sure 1st cube for this question. Then after finding the cube, I will hold the number of points that each cube consists.
My attempt: At first I thought if I compare my point with 8 corners it would be enough. I though that my point's coordinates must be greater then the 4 corners of the cube, and less then the remaining 4 corners of the cube and then I was going to iteratively increment the coordinates of the corner point to check for the other cubes. However, now I see that I am wrong.
What would be the best suiting algorithm for this problem?
Regards, Amadeus
note: I am using MATLAB, therefore if there are any built-in functions for this purpose, I can use them also.
Upvotes: 2
Views: 1585
Reputation: 2407
Lets say you have a cube N*N*N. And you create small cubes of dimension n*n*n. Then all cubes can be represented by a 3D array such that the cube with its closest edge to origin at ( a*n, b*n, c*n ) is represented by index (a, b , c) in this 3d array. And the value stored at that index is number of points inside that cube. Here is pseudo code
//Pseudo code
int [N/n][N/n][N/n] arrayWithCountOfPointsInsideCubes;
void function countPointsForCubes(double point_x, point_y, point_z)
{
arrayWithCountOfPointsInsideCubes[pint_x/n][point_y/n][point_z/n]++;
}
Upvotes: 0