MATLAB: How to shade the area between two mirror curves using patch

areapatchplotshade

Hello,
I wanted to shade the area between the curve C1 and C2 shown in the figure below.
The vector for curve C2 is:
alpha = 150 : 2 : 210;
pp = [cosd(alpha')+sind(60)+0.5 sind(alpha')+cosd(60)];
pp = flip(pp);
I am trying to shade the area using patch (shaded red in figure) but getting it shaded in other adjacent parts. Please do help and if you need any other information, comment below.

Best Answer

I am not certain how ‘C_1’ and ‘C_2’ were created, however this is one approach to filling the space between them (creating them as circle arcs):
t = linspace(-pi/4, pi/4); % Parameter Vector
r = 5; % Radius
x = r*cos(t); % x-Coordinate Of Curves
y = r*sin(t); % y-Coordinate Of Curves
xp(1,:) = x-r*1.25; % Left Side ‘x’ Vector
xp(2,:) = 1.25*r-x; % Right Side ‘x’ Vector
figure
plot(xp(1,:), y, '-k', xp(2,:), y, '-k') % Draw Curves
hold on
patch([xp(1,:) xp(2,:)], [y fliplr(y)], 'r') % Fill Between Curves
hold off
axis('equal')
producing:
.