How can I change the color between the two circles?
55 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
shreen elsapa
el 8 de Nov. de 2024 a las 17:28
Comentada: Voss
el 8 de Nov. de 2024 a las 21:11
% Parameters for the inner and outer circles
radius_inner = 1; % Radius of the inner (solid sphere)
radius_outer = 1.5; % Radius of the outer (porous shell)
% Create a figure
figure;
hold on;
axis equal;
% Generate points for the circles
theta = linspace(0, 2*pi, 100);
% Coordinates for the inner circle
x_inner = radius_inner * cos(theta);
y_inner = radius_inner * sin(theta);
% Coordinates for the outer circle
x_outer = radius_outer * cos(theta);
y_outer = radius_outer * sin(theta);
% Plot the outer circle and fill the area between circles with a color
fill([x_outer, fliplr(x_inner)], [y_outer, fliplr(y_inner)], [0.9, 0.9, 0.9], 'EdgeColor', 'k', 'FaceAlpha', 0.5); % Light gray color for the porous shell
% Plot the inner circle with a different color
fill(x_inner, y_inner, [0.8, 0.8, 0.8], 'EdgeColor', 'k'); % Darker gray color for solid sphere
% Set axis limits and hide axes
axis([-2 2 -2 2]);
axis off;
hold off;
0 comentarios
Respuesta aceptada
Voss
el 8 de Nov. de 2024 a las 17:31
Editada: Voss
el 8 de Nov. de 2024 a las 17:32
Change the third argument to the first fill() call. Example:
% Parameters for the inner and outer circles
radius_inner = 1; % Radius of the inner (solid sphere)
radius_outer = 1.5; % Radius of the outer (porous shell)
% Create a figure
figure;
hold on;
axis equal;
% Generate points for the circles
theta = linspace(0, 2*pi, 100);
% Coordinates for the inner circle
x_inner = radius_inner * cos(theta);
y_inner = radius_inner * sin(theta);
% Coordinates for the outer circle
x_outer = radius_outer * cos(theta);
y_outer = radius_outer * sin(theta);
% Plot the outer circle and fill the area between circles with a color
fill([x_outer, fliplr(x_inner)], [y_outer, fliplr(y_inner)], [0, 0.9, 0], 'EdgeColor', 'k', 'FaceAlpha', 0.5); % Green color for the porous shell
% Plot the inner circle with a different color
fill(x_inner, y_inner, [0.8, 0.8, 0.8], 'EdgeColor', 'k'); % Dark gray color for solid sphere
% Set axis limits and hide axes
axis([-2 2 -2 2]);
axis off;
hold off;
13 comentarios
Voss
el 8 de Nov. de 2024 a las 21:11
When viewing a 3d object in 2d, some parts of it will obscure some other parts. In this case, that means some pores in the annulus will appear in front of the inner sphere. Right?
Más respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!