Sphere packing using centroid and radius

7 visualizaciones (últimos 30 días)
Mithushan Soundaranathan
Mithushan Soundaranathan el 7 de Abr. de 2022
Editada: Moksh el 29 de Sept. de 2023
Hi,
I have dataset of centre points and radius of spheres in a packing (see attachment), I want to use that information to generated a image of my packing.
Basically I want generate 3D matrix with 0s and 1s, where 1s are part of spheres and 0s void space.
Could you please help me.
Best regards,
Mithu

Respuestas (1)

Moksh
Moksh el 27 de Sept. de 2023
Editada: Moksh el 29 de Sept. de 2023
Hi Mithushan,
I understand that there are centres and radii for several spheres in the attached text file and you wish to generate a 3d matrix where all the interior points of the spheres are marked as 1, while the remaining points are marked as 0.
You can try utilizing the “meshgrid” function in MATLAB and then use vector operations and comparisons to generate this type of matrix.
Here is an example code which shows this for a sample sphere:
% Dimensions of the matrix
matrixSize = [10, 10, 10];
% Center coordinates of the sphere
center = [5, 5, 5];
% Radius of the sphere
radius = 4;
% Generate the coordinates of the matrix
[X, Y, Z] = meshgrid(1:matrixSize(2), 1:matrixSize(1), 1:matrixSize(3));
% Calculate the distance from each point to the center of the sphere
distances = sqrt((X - center(1)).^2 + (Y - center(2)).^2 + (Z - center(3)).^2);
% Create the 3D matrix with 1s inside the sphere and 0s outside
matrix = distances <= radius;
% Plot the 3D matrix
figure;
isosurface(X, Y, Z, matrix, 0.5);
axis equal;
xlabel('X');
ylabel('Y');
zlabel('Z');
To generate the matrix for all the spheres, you can iterate over the text file using a loop and apply the same steps for each sphere. You can utilize the “fopen” and “textscan” functions in MATLAB to read a text file.
Please refer to the following documentation for more information about the mentioned functions:
Hope this information helps resolving the query.
Best Regards,
Moksh Aggarwal

Categorías

Más información sobre Geology en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by