How can I make sphere using smaller spheres?

2 Ansichten (letzte 30 Tage)
ka
ka am 11 Mai 2021
Bearbeitet: Jan am 14 Mai 2021
How can I make sphere of say unit length using smaller spheres of 1/4 length?
  2 Kommentare
Rik
Rik am 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 am 11 Mai 2021
You want to reproduce an image like this using MATLAB?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Jan
Jan am 11 Mai 2021
Bearbeitet: Jan am 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 Kommentare
Rik
Rik am 14 Mai 2021
What modifications to Jan's code have you tried?
Jan
Jan am 14 Mai 2021
Bearbeitet: Jan am 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by