
Fill area between circles
15 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Benjamin Salak
el 9 de Mzo. de 2020
Comentada: Benjamin Salak
el 9 de Mzo. de 2020
Lets say I have 2 circles. They are concentric about the origin. What is the best way to fill the area between the 2? I am using this circle function that I found on Mathworks. The larger circle has a diameter of 10 and the smaller circle has a diameter of 5.
function circle(d,x,y,ang_start,ang_end,step)
ang=ang_start:step:ang_end;
xp=(d/2)*cos(ang);
yp=(d/2)*sin(ang);
plot(x+xp,y+yp);
end
Thanks,
0 comentarios
Respuesta aceptada
the cyclist
el 9 de Mzo. de 2020
Here is one way:
% Get data for the two circles
[xp5, yp5] = circle(5,0,0,0,2*pi,0.01);
[xp10,yp10] = circle(10,0,0,0,2*pi,0.01);
% Draw the two circles
figure
hold on
plot(xp5,yp5)
plot(xp10,yp10)
% Fill in the area by defining the polygon that is defined by tracing the inner circle and then back along the outer circle
fill([xp5 flip(xp10)],[yp5 flip(yp10)],'g')
% Cover up the connecting line in the same color
h = line([xp5(1) xp10(end)],[yp5(1) yp10(end)]);
set(h,'Color','g')
% Set the axes to have equal length, so that they *look* like circles
axis equal

Más respuestas (0)
Ver también
Categorías
Más información sobre Polygons en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!