Filling a region in the complex plane in Matlab

7 views (last 30 days)
Abdullah Md Saifee on 10 Oct 2020
Answered: Walter Roberson on 11 Oct 2020
So I have plotted the the function defined implicitly by fimplicit in Matlab. I want to fill the region inside. How to do that?
f1=@(x,y) (1+x+x.^2-y.^2).^2+(y+2.*x.*y).^2-1;
fimplicit(f1)
hold on
axis([-1.5 0.5 -1.5 1.5])
xlabel('Re(h\lambda)')
ylabel('Im(h\lambda)')
hold off

Stanislao Pinzón on 11 Oct 2020
Maybe something like this:
f1=@(x,y) (1+x+x.^2-y.^2).^2+(y+2.*x.*y).^2-1;
V = fimplicit(f1);
hold on
axis([-1.5 0.5 -1.5 1.5])
xlabel('Re(h\lambda)')
ylabel('Im(h\lambda)')
fill(V.XData,V.YData,'r')

Walter Roberson on 11 Oct 2020
This turns out to be a bit tricky.
If you record the handle
h = fimplicit(f1);
then h.XData, h.YData are the vertex lists. The vertex lists are also available in several other places inside of h.
However... the XData, YData both have embedded NaN. It looks as if each place that the function has a major change in curvature, a different nan-separated group of vertices is started.
Now, you might expect "Okay, just delete the nan out of the vertex lists!", but it turns out that the groups are not in sequence, and also that there are definite gaps between the pieces.
Often, using boundary() can be used to adapt between a set of points and a continuous line, but boundary() does not get the (concave) indentations right.
I was not able to find any properties (including hidden ones) that indicated how the segments should be joined, or what order the segments should be in.
Notice the obvious gaps.
So although it appears to be possible to get the information about the discontinuous segments, interpreting the segment information is tricky.
I have not investigated the representation for the case where there is a real discontinuity in the plot, such as cases where the implicit plot should be two elipses.

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by