How can I change the color between the two circles?
55 views (last 30 days)
Show older comments
shreen elsapa
on 8 Nov 2024 at 17:28
Commented: Voss
on 8 Nov 2024 at 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 Comments
Accepted Answer
Voss
on 8 Nov 2024 at 17:31
Edited: Voss
on 8 Nov 2024 at 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 Comments
Voss
on 8 Nov 2024 at 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?
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!