How can I make sphere using smaller spheres?

2 vues (au cours des 30 derniers jours)
ka
ka le 11 Mai 2021
Modifié(e) : Jan le 14 Mai 2021
How can I make sphere of say unit length using smaller spheres of 1/4 length?
  2 commentaires
Rik
Rik le 11 Mai 2021
That depends on what you mean.
Have a read here and here. It will greatly improve your chances of getting an answer.
James Tursa
James Tursa le 11 Mai 2021
You want to reproduce an image like this using MATLAB?

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 11 Mai 2021
Modifié(e) : Jan le 11 Mai 2021
r = 0.1;
R = 1;
[x, y, z] = sphere(12);
w = linspace(-R + r, R - r, 1 + R / r);
figure;
axes('NextPlot', 'add', 'XLim', [-R, R], 'YLim', [-R, R], 'ZLim', [-R, R]);
for ix = w
for iy = w
for iz = w
if (ix)^2 + (iy)^2 + (iz)^2 <= R^2
surf(x * r + ix, y * r + iy, z * r + iz, ...
'FaceColor', [0.9, 0.9, 0.9], ...
'FaceLighting', 'gouraud', ...
'AmbientStrength', 0.5, ...
'DiffuseStrength', 0.6, ...
'EdgeColor', 'none');
end
end
end
end
view(3)
light
  5 commentaires
Rik
Rik le 14 Mai 2021
What modifications to Jan's code have you tried?
Jan
Jan le 14 Mai 2021
Modifié(e) : Jan le 14 Mai 2021
@Rishabh Katiyar: The 2nd image leaves some space between the spheres at the center amd uses another central instead of parallel projection. In addition it looks, like only spehere on the surface are created. Please try to implement this by your own.
For the first image:
r = 0.05;
R = 1;
[x, y, z] = sphere(12);
figure;
Lim = [-R-r, R+r];
axes('NextPlot', 'add', 'XLim', Lim, 'YLim', Lim, 'ZLim', Lim);
axis equal;
view(3);
light;
for theta = linspace(0, pi, 15)
for alpha = linspace(0, 2*pi, 24)
xs = sin(theta) * sin(alpha) * R;
ys = sin(theta) * cos(alpha) * R;
zs = cos(theta) * R;
surf(x * r + xs, y * r + ys, z * r + zs, ...
'FaceColor', [0.9, 0.9, 0.9], ...
'FaceLighting', 'gouraud', ...
'AmbientStrength', 0.5, ...
'DiffuseStrength', 0.6, ...
'EdgeColor', 'none');
end
end

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by