How can I calculate the number of points in subcubes of a big cube with random distribution. How can I calculate the distance between points
7 views (last 30 days)
I have this code with divides a big cube into 27 equal sized cubes.
N=100; % Number of points
cubesize = 100; % meter
subdivision = 3; % == 27^(1/3)
subcubesize = cubesize/subdivision;
% Generare N points in big cube V :) (0,cubsize)^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
h = slice([0 cubesize],[0 cubesize],[0 cubesize],zeros(2,2,2),...
I am using Rand to distribute points in big cube. How can i count the number of points in each small cube and the distance of each point in small cube from all other points in that same small cube.
Keyur Mistry on 22 Sep 2020
I understand you want to calculate number of points inside each sub cube and the distance between any two points inside a sub cube.
In the code provided by you, output variable ‘n’ is 3 x 3 x 3 matrix. In matrix ‘n’ there are 27 elements corresponding to each sub cube which gives number of points inside the sub cube. To find distance between any two points you can use the command ‘vecnorm’:
I hope this helps.