How can I change the color between the two circles?

조회 수: 55 (최근 30일)
shreen elsapa
shreen elsapa 2024년 11월 8일 17:28
댓글: Voss 2024년 11월 8일 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;

채택된 답변

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
shreen elsapa
shreen elsapa 2024년 11월 8일 20:38
@Voss not removed from the surface of a
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