How can I make sphere using smaller spheres?

2 次查看(过去 30 天)
How can I make sphere of say unit length using smaller spheres of 1/4 length?
  2 个评论
Rik
Rik 2021-5-11
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 2021-5-11
You want to reproduce an image like this using MATLAB?

请先登录,再进行评论。

采纳的回答

Jan
Jan 2021-5-11
编辑:Jan 2021-5-11
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 个评论
Rik
Rik 2021-5-14
What modifications to Jan's code have you tried?
Jan
Jan 2021-5-14
编辑:Jan 2021-5-14
@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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by