MATLAB: How to make sphere using smaller spheres

MATLAB and Simulink Student Suitesphere packing

How can I make sphere of say unit length using smaller spheres of 1/4 length?

Best Answer

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