I have random uniform distributed points in a 3D plot. How can I subdivide the plot into cube shaped grids with equal volume.

7 views (last 30 days)
My objective is to randomly and uniformly distribute points in a 3D cube shape. Then break the cube into 27 equal volume small cubes. then determine the density of points in each small cube (grid).
I have distributed points now but struggling to divide the plot into furether 27 sub cubes.
Help please
  6 Comments
Tamoor Shafique
Tamoor Shafique on 4 Sep 2020
I can modify 100 into 99 or any other value if this is easier. However, the code should be adaptive for dividing any cube into 27 small sub cubes is is possible?
Walter Roberson
Walter Roberson on 4 Sep 2020
the code should be adaptive for dividing any cube into 27 small sub cubes is is possible?
It gets messy. When the size of the larger cube is not divisible by 3, then there are 6 cut planes (2 per direction) along which it is necessary to figure out how to fairly count 1/3 or 2/3 of a pixel on each side of the cut plane. As you are calculating volumes, if you were to allocate the boundary pixel to both sides, then you would be over-estimating the volume.
A typical approach to try to be accurate and fair at the boundary involves looking at configurations of pixels at the boundary and saying that certain configurations of pixels count for one side or the other. For example if you have a conformation such as
*
*
**
*
and the boundary runs 1/3 of the way through the vertical line that has the single * then probably the fairest way would be to count it as being entirely on the right hand side, saying that the 1/3 of a pixel on the left of the boundary of what is clearly a surface, has "no significant presense" on the left side of the boundary and should only be counted on the right.
The major alternative is to count whole pixels that are entirely inside, and to count a fraction for one ones that are on the boundary.

Sign in to comment.

Accepted Answer

Bruno Luong
Bruno Luong on 4 Sep 2020
Edited: Bruno Luong on 4 Sep 2020
N=1e3; % Number of points
cubesize = 100; % meter
subdivision = 3; % == 27^(1/3)
subcubesize = cubesize/subdivision;
% Generare N points in big cube V :) (0,cubsize)^3
xyz=cubesize*rand(N,3);
% Compute the density of 27 small cubes
ijk = ceil(xyz/subcubesize);
n = accumarray(ijk,1,subdivision*ones(1,3));
density = n/subdivision^3 % #points per m^3 in each of 27 subcubes
close all
scatter3(xyz(:,1),xyz(:,2),xyz(:,3));
hold on
h = slice([0 cubesize],[0 cubesize],[0 cubesize],zeros(2,2,2),...
(0:3)*subcubesize,(0:3)*subcubesize,(0:3)*subcubesize);
set(h,'FaceColor','none')
axis equal
  11 Comments
Bruno Luong
Bruno Luong on 5 Sep 2020
It's just a middle point of the bigcube isn't it?
It's belong to the center subcube #(2,2,2)
That what you ask?
Tamoor Shafique
Tamoor Shafique on 5 Sep 2020
exactly. I could not distinguish that one since it is supposed to be the gateways or collector or sink node. I wanted to highlight it but I think you have helped me alot already I really appreciate this question is 99% solved.

Sign in to comment.

More Answers (0)

Categories

Find more on WSNs in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!