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