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
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
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
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
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.
0 comentarios
Respuestas (1)
Keyur Mistry
el 22 de Sept. de 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.
2 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!