How to create concentric circles?
15 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Yro
am 14 Jun. 2021
Kommentiert: Star Strider
am 15 Jun. 2021
Hello, I want to generate a series of concentric circles by filling each ring with a different color. The result I want to obtain is similar to the figure. With the code I present, I get the figure 2. How could I assign a color to each ring between the circles?
Thanks in advance
clear;
clc;
close all
x_center = 0;
y_center = 0;
pellet = 0.3355;
gap = 0.350;
w14re = 0.354;
re = 0.355;
clad = 0.455;
sicfib = 0.458;
radius_array = [pellet gap w14re re clad sicfib];
for i = 1:5
radius = 5;
theta = 0:pi/50:2*pi;
x_circle_1 = radius_array(i) * cos(theta) + x_center;
y_circle_1 = radius_array(i) * sin(theta) + y_center;
x_circle_2 = radius_array(i+1) * cos(theta) + x_center;
y_circle_2 = radius_array(i+1) * sin(theta) + y_center;
fig1 = plot(x_circle_1, y_circle_1, 'k-', 'LineWidth', 0.5);
hold on
fig2 = plot(x_circle_2, y_circle_2, 'k-', 'LineWidth', 0.5);
hold on
axis equal
axis off
end
0 Kommentare
Akzeptierte Antwort
Star Strider
am 15 Jun. 2021
x_center = 0;
y_center = 0;
pellet = 0.3355;
gap = 0.350;
w14re = 0.354;
re = 0.355;
clad = 0.455;
sicfib = 0.458;
radius_array = [pellet gap w14re re clad sicfib]
cm = turbo(numel(radius_array)); % Choose The Appropriate 'colormap'
for i = 1:5
radius = 5;
theta = 0:pi/50:2*pi;
x_circle_1 = radius_array(i) * cos(theta) + x_center;
y_circle_1 = radius_array(i) * sin(theta) + y_center;
x_circle_2 = radius_array(i+1) * cos(theta) + x_center;
y_circle_2 = radius_array(i+1) * sin(theta) + y_center;
fig1 = plot(x_circle_1, y_circle_1, 'k-', 'LineWidth', 0.5);
hold on
fig2 = plot(x_circle_2, y_circle_2, 'k-', 'LineWidth', 0.5);
patch([x_circle_1, fliplr(x_circle_2)], [y_circle_1, fliplr(y_circle_2)],cm(i,:), 'EdgeColor',cm(i,:))
hold on
axis equal
axis off
end
Note —
In the patch call, the EdgeColor is the color of the patch it encloses. To eliminate the edge colours instead, specify 'none' instead of cm(i,:).
.
2 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Polygons finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!