How can I make sphere using smaller spheres?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
How can I make sphere of say unit length using smaller spheres of 1/4 length?
2 Kommentare
Akzeptierte Antwort
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
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Surface and Mesh Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!