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

17 次查看(过去 30 天)
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 个评论
Tamoor Shafique
Tamoor Shafique 2020-9-4
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 2020-9-4
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.

请先登录,再进行评论。

采纳的回答

Bruno Luong
Bruno Luong 2020-9-4
编辑:Bruno Luong 2020-9-4
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 个评论
Tamoor Shafique
Tamoor Shafique 2020-9-5
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 WSNs 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by