How can I make sphere using smaller spheres?
2 views (last 30 days)
Show older comments
How can I make sphere of say unit length using smaller spheres of 1/4 length?
2 Comments
Accepted Answer
Jan
on 11 May 2021
Edited: Jan
on 11 May 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 Comments
Jan
on 14 May 2021
Edited: Jan
on 14 May 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
More Answers (0)
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!