Filling area between more curves

I am trying to colour the area between more curves (given also in implicite form) with one unbounded and transparent colour. This is example, how it should looks like (except from the red vertical line y=2):
And I have a same problem with planes. Is there any function to fill this "multiarea" or area between more surfaces?
I can only use fill, but it does not create comprehensive and transparent area between more curves.
Thank you.

 Accepted Answer

Change accordingly to suit your need.
tt = linspace(0,2*pi,361);
xy = [2*cos(tt);
4*sin(tt)];
close all
hold on
plot(xy(1,:), xy(2,:), 'k');
plot([-4 4],[0 0], 'k');
plot([-4 0],[-4 4], 'k');
plot([1 1],[-4 4], 'r');
b = [0; 1]'*xy >= 0 &...
[2; -1]'*xy >= [2; -1]'*[-2;0] ;
xyfill = [[-2;0] xy(:,b) [0; 4]];
patch('xdata',xyfill(1,:),'ydata',xyfill(2,:),'facecolor','b','facealpha',0.2, 'linewidth', 2);
axis equal
fill.png

11 Comments

Thank you,
What means b in your script?
blue color code
I am trying to understand the part:
b = [0; 1]'*xy >= 0 &...
[2; -1]'*xy >= [2; -1]'*[-2;0] ;
xyfill = [[-2;0] xy(:,b) [0; 4]];
What these define or what means values [0; 1], [2; -1] etc?
Thank you.
They are related to the half-plane define by the two lines that are parts of the areas you want to color.
  • The first one is
[0; 1]'*xy >= 0, meaning equivalent to y >= 0.
  • The second is
[2; -1]'*xy >= [2; -1]'*[-2;0] meaning equivalent to y <= 2*x + 4
I code them conveniently from the formula derived from normal N vector to the line and one point P belong to the line.
N' * [x; y] >= N' * P
Thank You.
And what if there would be for example three conics?
Bruno Luong
Bruno Luong on 16 Sep 2019
Edited: Bruno Luong on 16 Sep 2019
Just follow what I wrote: "Change accordingly to suit your need."
It is a lot of work to make a generic code based on "what if there would be for example three conics?".
Thanks, I got it.
And in 3D for surfaces it will works similar?
Not directly. A boundary of 3D object usually is usually a mesh.
Do You have an idea, how to do this for area bounded by surfaces?
Thank You.
Possibly, here is a simple example
Thank You. I will explore that.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!