How can I change the color between the two circles?

55 次查看(过去 30 天)
% 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;

采纳的回答

Voss
Voss 2024-11-8,17:31
编辑:Voss 2024-11-8,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 个评论
Voss
Voss 2024-11-8,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?

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by