Sphere packing using centroid and radius

조회 수: 6 (최근 30일)
Mithushan Soundaranathan
Mithushan Soundaranathan 2022년 4월 7일
편집: Moksh 2023년 9월 29일
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

답변 (1개)

Moksh
Moksh 2023년 9월 27일
편집: Moksh 2023년 9월 29일
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

카테고리

Help CenterFile Exchange에서 Geology에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by