- meshgrid: https://in.mathworks.com/help/matlab/ref/meshgrid.html
- isosurface: https://in.mathworks.com/help/matlab/ref/isosurface.html
- fopen: https://in.mathworks.com/help/matlab/ref/fopen.html
- textscan: https://in.mathworks.com/help/matlab/ref/textscan.html
Sphere packing using centroid and radius
7 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Moksh
le 27 Sep 2023
Modifié(e) : Moksh
le 29 Sep 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
0 commentaires
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!