title: Matlab: Why is the fill function not filling the area between two circles?
body: <p>I'm trying to fill the intersecting area between two circles in Matlab. I've quite literally copied and pasted this piece of code from <a href="https://www.mathworks.com/matlabcentral/answers/267866-how-we-can-generate-a-union-area-of-overlapping-2-circles-3-circles-multiple-n-circles" rel="nofollow noreferrer">this</a> article on Matlab Central. </p>
  
  <pre><code>t = linspace(0, 2*pi, 100);
  cir = @(r,ctr) [r*cos(t)+ctr(1); r*sin(t)+ctr(2)]; % Circle Function
  c1 = cir(1.0, [0; 0]);
  c2 = cir(1.5, [1; 1]);
  in1 = find(inpolygon(c1(1,:), c1(2,:), c2(1,:), c2(2,:))); % Circle #1 Points Inside Circle #2
  in2 = find(inpolygon(c2(1,:), c2(2,:), c1(1,:), c1(2,:))); % Circle #2 Points Inside Circle #1
  [fillx,ix] = sort([c1(1,in1) c2(1,in2)]); % Sort Points
  filly = [c1(2,in1) (c2(2,in2))];
  filly = filly(ix);
  figure(1)
  plot(c1(1,:), c1(2,:))
  hold on
  plot(c2(1,:), c2(2,:))
  fill([fillx fliplr(fillx)], [filly fliplr(filly)], 'g', 'EdgeColor','none')
  hold off
  axis square
  </code></pre>
  
  <p>What I end up with is the following image:</p>
  
  <p><a href="https://i.stack.imgur.com/Iu6Dt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Iu6Dt.jpg" alt="enter image description here"></a> </p>
  
  <p>However, it should appear as this image:</p>
  
  <p><a href="https://i.stack.imgur.com/Ki4kF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Ki4kF.png" alt="enter image description here"></a></p>
  
  <p>Why is the area not being filled as it is in the example article? </p>